Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MessageManager

The MessageManager class provides a set of services related to sending and receiving messages between the client and server. Each connection has only one MessageManager, which is created automatically, and can be accessed via getMessageManager() method.

Hierarchy

  • MessageManager

Index

Constructors

constructor

Properties

removeListenersOnDisconnect

removeListenersOnDisconnect: boolean = true

Methods

addMessageListener

  • addMessageListener(message: string, listener: Function, thisArg?: any, forRoomIDs?: string[]): boolean
  • Registers a method or function (hereafter, the "message listener") to be executed when the specified type of message is received from the server. The message can be a built-in UPC message, or a custom message sent to the client by a server-side module or by another client via the sendMessage() method of the Room, RoomManager, Client, ClientManager, or Server classes. Messages listeners are executed in the order they were added.

    Typically, MessageManager.addMessageListener method is not used to register listeners for messages sent via Room.sendMessage method. Messages sent to a single room via Room's sendMessage() method are normally handled by listeners registered using the Room class's addMessageListener() method instead of MessageManager's addMessageListener(). The Room class's version of addMessageListener() provides a convenient wrapper for the functionality provided by MessageManager's addMessageListener().

    MessageManager's addMessageListener() method can be used to register listeners that handle messages centrally for a group of rooms. For example, suppose a multi-room chat application displays a notification icon when a new message is received in any room. To catch all incoming messages for all rooms, the application registers a single, centralized method for all "CHAT" messages.

    Parameters

    • message: string

      The name of the message the listener is registering to receive.

    • listener: Function

      The function or method that will be invoked when the specified message is received. The rules describing the required datatypes of the listener's parameters are listed under the addMessageListener() method documentation.

    • Optional thisArg: any
    • Optional forRoomIDs: string[]

      A list of room IDs. If the message was sent to any of the rooms in the list, the listener is executed. Otherwise, the listener is not executed. Applies to messages sent to rooms only, not to messages sent to specific individual clients or the entire server.

    Returns boolean

dispose

  • dispose(): void
  • Returns void

getNumMessagesReceived

  • getNumMessagesReceived(): number
  • Returns the number of messages that have been received by the MessageManager. Used for statistics tracking and load testing.

    Returns number

getNumMessagesSent

  • getNumMessagesSent(): number
  • Returns the number of messages that have been sent by the MessageManager. Used for statistics tracking and load testing.

    Returns number

getTotalMessages

  • getTotalMessages(): number
  • Returns the number of messages that have been sent and received by the MessageManager. Used for statistics tracking and load testing.

    Returns number

hasMessageListener

  • hasMessageListener(message: string, listener: Function): boolean
  • Returns a Boolean indicating whether the specified listener function is currently registered to receive message notifications for the specified message.

    Parameters

    • message: string
    • listener: Function

    Returns boolean

removeMessageListener

  • removeMessageListener(message: string, listener: Function): boolean
  • Unregisters a message listener method that was earlier registered for message notifications via addMessageListener().

    Note that by default, all message listeners are automatically removed when the connection to the server is closed.

    Parameters

    • message: string
    • listener: Function

    Returns boolean

sendUPC

  • sendUPC(message: string, ...args: (string | number | undefined)[]): void
  • Creates and sends a UPC-formatted message to the server. This method is used internally to send UPC-formatted messages to the server. Any UPC-formatted response from the server will trigger a ConnectionEvent.RECEIVED_UPC event.

    Parameters

    • message: string
    • Rest ...args: (string | number | undefined)[]

    Returns void

sendUPCObject

  • sendUPCObject(upc: UPC): void
  • Parameters

    Returns void

toString

  • toString(): string
  • Returns string