Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ClientManager

The ClientManager class provides centralized access to Client instances, which represent clients connected to Union Server. Any client that is known to the current client (for example, a client in the same room as the current client) can be accessed via ClientManager.getClient method.

Hierarchy

  • EventDispatcher
    • ClientManager

Index

Constructors

constructor

Properties

Readonly target

target: EventDispatcher

Methods

addEventListener

  • addEventListener(type: string, listener: Function, thisArg: any, priority?: number): boolean
  • Parameters

    • type: string
    • listener: Function
    • thisArg: any
    • Default value priority: number = 0

    Returns boolean

ban

  • ban(address: string, duration: number, reason: string): void
  • Disconnects any clients with the specified address (typically an IP address) and prevents any future client connections from that address. By default, ban() requires administrator privileges. To allow other types of clients (such as moderators) to ban addresses, define a remote-client security rule.

    The result of the ban attempt is returned via a ClientManagerEvent.BAN_RESULT event.

    Parameters

    • address: string

      The address to ban (typically an IP address).

    • duration: number

      The duration of the ban, in seconds.

    • reason: string

      An arbitrary, optional string indicating the reason for the ban. The reason string is saved in the server-side ban list.

    Returns void

clientIsKnown

  • clientIsKnown(clientID: string): boolean
  • Returns a Boolean indicating whether the client with the specified clientID is known to the current client. The client is "known" in the following situations:

    • The ClientManager is watching for clients, and a client with the specified id is connected to Union Server. See the ClientManager.watchForClients method.
    • The client with the specified clientID is in a room that the current client is either in or observing, and the current client's update levels for the room include occupant-list updates (see the UpdateLevels class).
    • The client with the specified clientID is observing a room that the current client is either in or observing, and the current client's update levels for the room include observer-list updates (see the UpdateLevels class).
    • The current client is observing the client with the specified clientID. See ClientManager.observeClient method.
    • The client with the specified clientID is logged in, and the current client is watching for user accounts. See AccountManager.watchForAccounts method.
    • The client with the specified clientID is logged into an account being observed by the current client. See AccountManager.observeAccount method.
    • The client with the specified clientID is the current client.

    Parameters

    • clientID: string

    Returns boolean

dispatchEvent

  • dispatchEvent(event: Event): void
  • Parameters

    • event: Event

    Returns void

dispose

  • dispose(): void
  • Permanently disables this object. The object cannot be reused. The dispose() method's purpose is to put this object into a state in which it can be garbage collected.

    Returns void

fireBanClientResult

  • fireBanClientResult(address: string, clientID: string, status: Status): void
  • Parameters

    • address: string
    • clientID: string
    • status: Status

    Returns void

getAttributeForClients

  • getAttributeForClients(clientIDs: string[], attrName: string, attrScope?: undefined | string): { clientID: string; value: string | null }[]
  • Returns an array of objects containing values for the specified attribute for all clients in supplied clientIDs. Each object in the returned array has a clientID property (giving the client id), and a value property (giving the attribute value). The value property will be null for clients in clientIDs that either do not exist or do not have a value set for the specified attribute.

    For information on client attributes see the Client.setAttribute method.

    Parameters

    • clientIDs: string[]

      An array of client ids indicating the clients for which to retrieve the specified attribute.

    • attrName: string

      The name of the attribute to retrieve.

    • Optional attrScope: undefined | string

      The scope of the attribute to retrieve. Omit for global attributes.

    Returns { clientID: string; value: string | null }[]

getBannedAddresses

  • getBannedAddresses(): string[]
  • Returns string[]

getClient

  • getClient(clientID: string, scope?: undefined | string): Client | null
  • Returns an object representing the specified client; by default, the object is an instance of the Client class. However, if a custom class has been specified for the client in the specified scope, the object will be an instance of that custom class.

    Parameters

    • clientID: string

      The server-generated client ID for the client.

    • Optional scope: undefined | string

      An optional fully qualified room id (e.g., "examples.chatRoom").

    Returns Client | null

getClientByAttribute

  • getClientByAttribute(attributeName: string, attributeValue: string, attributeScope?: undefined | string, roomScope?: undefined | string): Client | null
  • Returns the first client known to the ClientManager that has an attribute name and value matching the specified attribute name and value. If no client has a matching attribute, returns null.

    Parameters

    • attributeName: string

      The name of the attribute to match.

    • attributeValue: string

      The value of the attribute to match.

    • Optional attributeScope: undefined | string

      The scope of the attribute to match. Use undefined for global.

    • Optional roomScope: undefined | string

      A fully qualified room id (e.g., "examples.chatRoom"). For details, see the "scope" parameter of the getClient method.

    Returns Client | null

getClientByUserID

  • getClientByUserID(userID: string, scope?: undefined | string): Client | null
  • Returns the client that is logged into the account specified by userID. If no known client is logged in under the specified userID, returns null.

    Parameters

    • userID: string

      A user account's userID.

    • Optional scope: undefined | string

      A fully qualified room id (e.g., "examples.chatRoom"). For details, see the "scope" parameter of the ClientManager.getClient method.

    Returns Client | null

getClients

  • Returns a list of all client objects known to the current client. Each client object in the list is an instance of either Client or a custom client class.

    Returns Client[]

getDefaultClientClass

  • getDefaultClientClass(): any
  • Returns the class used as the global default class for clients in this application.

    Returns any

getInternalClient

  • getInternalClient(clientID: string): Client | null
  • Returns the internal Client object for the specified client id. This method is required in one situation only: when an application specifies a custom client class that does not extend CustomClient, it must implement IClient directly, and compose a Client instance. To obtain the composed instance, the custom class must use getInternalClient(). Otherwise, client applications should retrieve Client objects via getClient, not getInternalClient.

    Parameters

    • clientID: string

      The server-generated client ID.

    Returns Client | null

getInternalClients

  • getInternalClients(): {}
  • Returns a hash of Client objects known to the current client, where the hash keys are client IDs, and the hash values are Client objects. Contrast with getClients, whose client objects are instances custom client classes for any client that specifies a custom client class. Because getInternalClients() performs no custom-client-class lookup, is faster than getClients().

    Returns {}

getLifetimeNumClientsKnown

  • getLifetimeNumClientsKnown(): number
  • Returns the total number of clients that have ever been known to the current client, excluding itself.

    Returns number

getListeners

  • getListeners(type: string): EventListener[]
  • Parameters

    • type: string

    Returns EventListener[]

getNumClients

  • getNumClients(): number
  • Returns the number of clients known to Orbiter. When the ClientManager is watching for clients (see watchForClients), getNumClients() returns the actual number of clients currently connected to Union Server. When the ClientManager is not watching for clients, getNumClients() returns only the number of clients about which the current client is aware. For example, if the current client is in a room with three other clients, and has no other awareness of clients on the server, then getNumClients() will return 4, even though more than 4 clients might be connected to the server.

    Returns number

getNumClientsOnServer

  • getNumClientsOnServer(): number
  • If the ClientManager is watching for clients, getNumClientsOnServer() returns the number of clients on the server; otherwise, getNumClientsOnServer() returns 0. When the ClientManager is watching for clients, the getNumClientsOnServer() method provides a faster alternative to getNumClients().

    Returns number

hasListener

  • hasListener(type: string, listener: Function, thisArg: any): boolean
  • Parameters

    • type: string
    • listener: Function
    • thisArg: any

    Returns boolean

hasWatchedClient

  • hasWatchedClient(clientID: string): boolean
  • Returns true if the client with the specified clientID is in the watched client list; false otherwise.

    Parameters

    • clientID: string

    Returns boolean

isObservingClient

  • isObservingClient(clientID: string): boolean
  • Returns true if the client with the specified clientID is currently being observed; false otherwise.

    Parameters

    • clientID: string

    Returns boolean

isWatchingForBannedAddresses

  • isWatchingForBannedAddresses(): boolean
  • Returns boolean

isWatchingForClients

  • isWatchingForClients(): boolean
  • Indicates whether the current client is currently watching for clients.

    Returns boolean

kickClient

  • kickClient(clientID: string): void
  • Disconnects the specified client from the server. By default, requires moderator privileges.

    The result of the kick attempt is returned via a ClientManagerEvent.KICK_RESULT event.

    Parameters

    • clientID: string

      The clientID of the client to kick.

    Returns void

observeClient

  • observeClient(clientID: string): void
  • Asks the server to register the current client as an observer of the client specified by clientID. The result of the request is returned via a ClientEvent.OBSERVE_RESULT event triggered by the ClientManager. If the request succeeds, Orbiter creates a Client object for the client (if one does not already exist), and a ClientEvent.OBSERVE event is triggered by the ClientManager. The Client object is then synchronized with the server-side state of the client. Subsequently if the specified client's state changes, the current client is notified in the following ways:

    • Observed client's attribute changes: the Client object triggers a AttributeEvent.UPDATE event
    • Observed client's attribute is deleted: the Client object triggers a AttributeEvent.DELETE event
    • Observed client joins a room: the Client object triggers a ClientEvent.JOIN_ROOM event
    • Observed client leaves a room: the Client object triggers a ClientEvent.LEAVE_ROOM event
    • Observed client observes a room: the Client object triggers a ClientEvent.OBSERVE_ROOM event
    • Observed client stops observing a room: the Client object triggers a ClientEvent.STOP_OBSERVING_ROOM event
    • Observed client logs into a user account: current client's AccountManager triggers an AccountEvent.LOGIN event
    • Observed client logs off of a user account: current client's AccountManager triggers an AccountEvent.LOGOFF event
    • Observed client disconnects: current client's ClientManager triggers the ClientManagerEvent.CLIENT_DISCONNECTED event

    To stop observing a client, use Client.stopObserving method.

    Client observation is used when a client wishes to stay informed of the state of an arbitrary list of clients, as is typical in applications with client match-making or administrative interfaces.

    Parameters

    • clientID: string

      The clientID of the client to observe.

    Returns void

removeEventListener

  • removeEventListener(type: string, listener: Function, thisArg: any): boolean
  • Parameters

    • type: string
    • listener: Function
    • thisArg: any

    Returns boolean

sendMessage

  • sendMessage(messageName: string, clientIDs: string[], filters: Filter | null, ...rest: string[]): void
  • Sends a message to a set of specified clientIDs. To send a message to a single client only, use Client.sendMessage method. To receive the message, recipient clients must register a message listener via MessageManager.addMessageListener method.

    Parameters

    • messageName: string

      The name of the message to send.

    • clientIDs: string[]

      An array of the recipient client ID(s) for the message.

    • filters: Filter | null

      Specifies one or more filters for the message. A filter specifies a requirement that each client must meet in order to receive the message. For example, a filter might indicate that only those clients with the attribute "team" set to "red" should receive the message. If filters is null, all specified clients receive the message.

    • Rest ...rest: string[]

      An optional comma-separated list of string arguments for the message. These will be passed to any listeners registered to receive the message. See MessageManager.addMessageListener method.

    Returns void

setDefaultClientClass

  • setDefaultClientClass<T>(defaultClass: {}): void
  • Assigns a class to use as the default class for all clients in the application.

    By default, all clients are represented by instances of the Client class. An application can, however, choose to represent clients with a custom class. The custom client class can be specified on a per-client basis via the Client.setClientClass method. Or, the custom class can be specified on a per-room basis via the Room.setDefaultClientClass method. Or, the custom class can be specified globally via the ClientManager class's setDefaultClientClass() method. When a class has been specified globally via setDefaultClientClass(), it is used as the client class for any client retrieved via ClientManager.getClient method with an unspecified scope.

    Any custom class specified via Room's setDefaultClientClass() method overrides the global default client class. Similarly, any custom class specified via Client's setClientClass() method overrides the room and global default client class.

    Type parameters

    • T

    Parameters

    • defaultClass: {}

      The global default client class. The class is normally a descendant of CustomClient.

    Returns void

stopWatchingForBannedAddresses

  • stopWatchingForBannedAddresses(): void
  • Asks the server to stop watching for banned addresses. In response, the server no longer sends notifications when an addresses is banned or unbanned.

    The result of a stopWatchingForBannedAddresses() request is returned via a ClientManagerEvent.STOP_WATCHING_FOR_BANNED_ADDRESSES_RESULT event.

    Returns void

stopWatchingForClients

  • stopWatchingForClients(): void
  • Asks the server to stop watching for clients. In response, the server no longer sends notifications when a client connects or disconnects. The result of a stopWatchingForClients() request is returned via ClientManagerEvent.STOP_WATCHING_FOR_CLIENTS_RESULT.

    Returns void

unban

  • unban(address: string): void
  • Removes any ban currently in effect for the specified address (typically an IP address). By default, unban() requires administrator privileges. To allow other types of clients (such as moderators) to unban addresses, define a remote-client security rule.

    Parameters

    • address: string

      The address to unban (typically an IP address).

    Returns void

watchForBannedAddresses

  • watchForBannedAddresses(): void
  • Asks the server to send its list of banned client addresses, and then send notification any time an address is banned or unbanned. When the banned list is ready, ClientManager dispatches a ClientManagerEvent.SYNCHRONIZE_BANLIST event. Subsequently, when a client address is banned, ClientManager dispatches a ClientManagerEvent.ADDRESS_BANNED event and when a client address is unbanned, ClientManager dispatches a ClientManagerEvent.ADDRESS_UNBANNED event.

    The result of a watchForBannedAddresses() request is returned via a ClientManagerEvent.WATCH_FOR_BANNED_ADDRESSES_RESULT event.

    By default, watchForBannedAddresses() requires administrator privileges. To allow other types of clients (such as moderators) to access the banned address list, define a remote-client security rule.

    Returns void

watchForClients

  • watchForClients(): void
  • Asks the server to send a list of clients currently connected to the server, and then send notification any time a client connects or disconnects. When the client list is ready, ClientManager dispatches a ClientManagerEvent.SYNCHRONIZE event. Subsequent client connections trigger a ClientManagerEvent.CLIENT_CONNECTED event. Subsequent disconnections trigger a ClientManagerEvent.CLIENT_DISCONNECTED event.

    Clients that are added to the ClientManager's client list in response to watchForClients() do not have attributes loaded. To load attributes for a specific client, use Client.observe method or ClientManager.observeClient method. In the default configuration, attributes can also be loaded for a given client by joining a room containing that client.

    As an alternative to watchForClients(), applications can maintain an arbitrary shared list of clients (with attributes automatically loaded or not) by creating an application room and then forcing all clients in the application to join that room. Clients wishing to load the list without being included in it can observe the application room and register for RoomEvent.ADD_OCCUPANT and RoomEvent.REMOVE_OCCUPANT events. Clients in the list can ignore client list updates by turning off updates for the room via the Room class's setUpdateLevels() method. In applications that wish to manage client lists, room-based client lists are normally more appropriate than watchForClients(). The watchForClients() method is intended for use primarily in cases where the list of rooms and clients on Union Server is not known in advance, and cannot be controlled (as is often true for server-administration applications). As a final alternative to watchForClients(), applications can use the ClientListSnapshot class to load a one-time list of clients on the server.

    The result of a watchForClients() request is returned via a ClientManagerEvent.WATCH_FOR_CLIENTS_RESULT event.

    Returns void