Options
All
  • Public
  • Public/Protected
  • All
Menu

Class UserAccount

The UserAccount class represents a Union user account. Each user account can save information in persistent attributes, which are stored in a server-side database or other custom datasource. User accounts are created with the AccountManager class's createAccount() method. Clients login to user accounts via the AccountManager class's login() method. When a client logs in, its Client object is linked with a UserAccount object. To access the account's events and data, use the Client class's getAccount() method, which returns a UserAccount object.

When a client logs into an account, that account's global attributes are loaded automatically, and are immediately available via UserAccount's getAttribute() method. Account attributes scoped to a room are loaded automatically when the logged-in client joins or observes that room.

To access the list of UserAccount objects known to the current client, use the AccountManager class's getAccounts() method.

Hierarchy

  • EventDispatcher
    • UserAccount

Index

Constructors

constructor

  • Constructor. Developers need not invoke the UserAccount constructor directly; Orbiter automatically creates UserAccount objects when clients login.

    Parameters

    Returns UserAccount

Properties

Readonly target

target: EventDispatcher

Static FLAG_MODERATOR

FLAG_MODERATOR: number = 1 << 1

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

addRole

  • Adds a new security role to the account.

    Parameters

    Returns void

changePassword

  • changePassword(newPassword: string, oldPassword: string): void
  • Changes the account's password.

    Parameters

    • newPassword: string

      The desired new account password. Must not be null.

    • oldPassword: string

      The current account password. If no password is supplied, the password will be changed if the client requesting the change has sufficient privileges only.

    Returns void

deleteAttribute

  • deleteAttribute(attrName: string, attrScope: string): void
  • Deletes an attribute from this user account.

    Parameters

    • attrName: string
    • attrScope: string

    Returns void

dispatchEvent

  • dispatchEvent(event: Event): void
  • Parameters

    • event: Event

    Returns void

getAttribute

  • getAttribute(attrName: string, attrScope?: undefined | string): string | null
  • Retrieves a persistent client attribute. This UserAccount's persistent attributes are available only when this UserAccount is synchronized with the state of the server.

    To synchronize an account, the current client must do one of the following:

    • Join a room containing the account's logged-in client, and set sufficiently verbose room-update levels for the room
    • Observe a room containing the account's logged-in client, and set sufficiently verbose room-update levels for the room

    For general details on retrieving attributes, see the Client.getAttribute method.

    Parameters

    • attrName: string
    • Optional attrScope: undefined | string

    Returns string | null

getAttributes

  • getAttributes(): {} | null
  • Returns an object containing all attributes for this user account. The object's structure matches that of the analogous Client.getAttributes.

    Returns {} | null

getAttributesByScope

  • getAttributesByScope(scope: string): {} | {} | null
  • Returns an object containing the names and values of all attributes defined on this UserAccount instance for a given scope, or for all scopes. The object's structure matches that of the analogous Client.getAttributesByScope.

    Parameters

    • scope: string

    Returns {} | {} | null

getClient

  • Returns a reference to this account's Client object, which is available if this account is logged in only.

    Returns Client | CustomClient | null

getConnectionState

  • Indicates whether this UserAccount is currently logged in.

    Returns ConnectionState

    An integer corresponding to one of the following three constants: ConnectionState.LOGGED_IN, ConnectionState.NOT_CONNECTED, or ConnectionState.UNKNOWN.

getInternalClient

  • getInternalClient(): Client | null
  • Returns the internal Client object for this account's corresponding client. This method is required when an application wishes to access the composed Client object reference for a client with a custom client class. For details, see the ClientManager.getInternalClient method.

    Returns Client | null

getListeners

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

    • type: string

    Returns EventListener[]

getUserID

  • getUserID(): string
  • Returns this account's userID.

    Returns string

hasListener

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

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

    Returns boolean

isLoggedIn

  • isLoggedIn(): boolean
  • Returns true if this user account's connection state is ConnectionState.LOGGED_IN; false otherwise.

    Returns boolean

isModerator

  • isModerator(): boolean
  • Returns a Boolean indicating whether the account has moderator privileges. To assign moderator privileges to an account, use addRole().

    Returns boolean

    true if the account has moderator privileges, false otherwise.

isSelf

  • isSelf(): boolean
  • Returns true if the current client is logged in under this UserAccount.

    Returns boolean

logoff

  • logoff(password?: undefined | string): void
  • Logs off this user account. The result of the attempt is returned via an AccountEvent.LOGOFF_RESULT event. If the attempt succeeds, the UserAccount object triggers an AccountEvent.LOGOFF event and the corresponding client is then automatically disconnected by Union Server.

    Parameters

    • Optional password: undefined | string

      The account's password. If no password is supplied, the account will be logged off if the client requesting the logoff has sufficient privileges only.

    Returns void

observe

  • observe(): void
  • Asks the server to notify the current client any time this UserAccount's state changes. For complete details, see the AccountManager's observeAccount() method.

    Returns void

removeEventListener

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

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

    Returns boolean

removeRole

  • removeRole(userID: string, role: string): void
  • Removes a security role from the account.

    Parameters

    • userID: string
    • role: string

    Returns void

setAttribute

  • setAttribute(attrName: string, attrValue: string, attrScope: string, isShared: boolean, evaluate: boolean): void
  • Assigns an account attribute that is stored persistently on the server under this user account.

    Note that a logged-in client's attribute names do not conflict with its account attribute names. For example, a client might define an attribute "score" on itself and also on its user account. The two attributes are considered separate; each can have its own value.

    For general details on assigning attributes, see the Client.setAttribute method.

    Parameters

    • attrName: string
    • attrValue: string
    • attrScope: string
    • isShared: boolean
    • evaluate: boolean

    Returns void

stopObserving

  • stopObserving(): void
  • Asks the server to stop observing this UserAccount. As a result, the server will no longer send notifications when the UserAccount's state changes.

    Results of a stopObserving() call are returned via a AccountEvent.STOP_OBSERVING_RESULT event. If the call succeeds, the AccountEvent.STOP_OBSERVING event is also triggered.

    Returns void

toString

  • toString(): string
  • Returns string