Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AccountManager

The AccountManager class provides control over Union user accounts. A Union user account gives a user:

  • a persistent identity on the server
  • the ability to store information in a server-side data source

Users that have created an account and logged in can save account attributes permanently using the UserAccount.setAttribute method. When a user logs in, all global account attributes for the user's account are automatically loaded. Room-scoped account attributes are automatically loaded as the user account's corresponding client joins or observes rooms.

Hierarchy

  • EventDispatcher
    • AccountManager

Index

Constructors

constructor

Properties

Readonly target

target: EventDispatcher

Methods

accountIsKnown

  • accountIsKnown(userID: string): boolean
  • Returns a Boolean indicating whether the user account with the specified userID is known to the current client. A given user account is known to the current client in the following situations:

    • the current client is in or observing a room with an occupant logged in under the specified userID, and the current client's room-update levels for the room include occupant-login notifications
    • the current client is in or observing a room with an observer logged in under the specified userID, and the current client's room-update levels for the room include observer-login notifications
    • the current client is observing the specified user account
    • the current client is observing a client logged in under the specified userID
    • the current client is watching for user accounts (see watchForAccounts) and the specified user account exists on the server
    • the current client is watching for clients (see ClientManager.watchForClients method) and a connected client is logged into the specified user account
    • the current client is logged in under the specified user account

    Parameters

    • userID: string

    Returns boolean

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

  • addRole(userID: string, role: string): void
  • Adds a new security role to a user account. The result of the add-role attempt is returned via an AccountEvent.ADD_ROLE_RESULT event, which is dispatched both via the AccountManager and also via the UserAccount object for which the new role was requested. If no such account is known, the event is dispatched via the AccountManager only.

    Parameters

    • userID: string

      The account's userID.

    • role: string

      The desired new role. For a list of built-in security roles, see the SecurityRole class.

    Returns void

changePassword

  • changePassword(userID: string, newPassword: string, oldPassword?: undefined | string): void
  • Changes a user-account password. The result of the password-change attempt is returned via an AccountEvent.CHANGE_PASSWORD_RESULT event, which is dispatched both via the AccountManager and also via the UserAccount object for which the change was requested. If no such account is known, the event is dispatched via the AccountManager only.

    Parameters

    • userID: string

      The account's userID.

    • newPassword: string

      The desired new account password.

    • Optional oldPassword: undefined | string

      The account's existing password. If no password is supplied, the password is changed only if the client requesting the change has sufficient privileges.

    Returns void

createAccount

  • createAccount(userID: string, password: string): void
  • Creates a user account, which is used to store persistent user information such as an age, a travel booking, or a high score. The result of the account-creation attempt is returned via an AccountManagerEvent.CREATE_ACCOUNT_RESULT event. Once an account is created, a client can login to that account using AccountManager.login method.

    Parameters

    • userID: string
    • password: string

    Returns void

dispatchEvent

  • dispatchEvent(event: Event): void
  • Parameters

    • event: Event

    Returns void

fireObserveAccountResult

  • fireObserveAccountResult(userID: string, status: Status): void
  • Parameters

    • userID: string
    • status: Status

    Returns void

getAccount

  • getAccount(userID?: undefined | string): UserAccount | null
  • Returns a reference to the account with the specified userID, if the account is known to Orbiter. If the account is unknown, returns null.

    Parameters

    • Optional userID: undefined | string

      A user account's userID.

    Returns UserAccount | null

getAccounts

  • getAccounts(): {}

getClientsForObservedAccounts

  • getClientsForObservedAccounts(): {}
  • Returns {}

getListeners

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

    • type: string

    Returns EventListener[]

getNumAccounts

  • getNumAccounts(): number
  • Returns the number of known user accounts. When the AccountManager is watching for user accounts (see watchForAccounts), getNumAccounts returns the actual number of user accounts registered on the server. When the AccountManager is not watching for clients, getNumAccounts() returns only the number of accounts known to the current client. For example, if the current client is observing three accounts, and has no other awareness of accounts on the server, then getNumAccounts() will return 3, even though more than 3 accounts might be registered on the server.

    Returns number

getNumAccountsOnServer

  • getNumAccountsOnServer(): number
  • If the AccountManager is watching for accounts, getNumAccountsOnServer returns the number of accounts on the server; otherwise, getNumAccountsOnServer returns 0. When the AccountManager is watching for accounts, the getNumAccountsOnServer() method provides a faster alternative to getNumAccounts().

    Returns number

getNumLoggedInAccounts

  • getNumLoggedInAccounts(): number
  • Returns the number of known, logged-in user accounts.

    Returns number

hasListener

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

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

    Returns boolean

hasWatchedAccount

  • hasWatchedAccount(userID: string): boolean
  • Returns true if the account with the specified userID is in the watched account list; false otherwise.

    Parameters

    • userID: string

    Returns boolean

isObservingAccount

  • isObservingAccount(userID: string): boolean
  • Returns true if the account with the specified userID is currently being observed; false otherwise.

    Parameters

    • userID: string

    Returns boolean

isWatchingForAccounts

  • isWatchingForAccounts(): boolean
  • Indicates whether the current client is currently watching for accounts.

    Returns boolean

login

  • login(userID: string, password: string): void
  • Logs in the current client using the specified userID and password. The result of the login attempt is returned via an AccountEvent.LOGIN_RESULT event triggered by the AccountManager.

    If the attempt succeeds, the AccountManager and the UserAccount object for the current client trigger an AccountEvent.LOGIN event, and the account's persistent attributes are automatically loaded. If the specified userID is already logged in under another client ID, the previous client is logged off and disconnected before the new login proceeds.

    Room-scoped persistent account attributes are automatically loaded when the current client joins or observes rooms. If the current client is already in or observing a room when it logs in, the room-scoped attributes for that room are also loaded at login time.

    The login() method cannot be used to login foreign clients; it applies to the current client only.

    Parameters

    • userID: string
    • password: string

    Returns void

logoff

  • logoff(userID: string | null, password?: undefined | string): void
  • Logs off a user account. The result of the logoff attempt is returned via an AccountEvent.LOGOFF_RESULT event, which is dispatched both via the AccountManager and also by the UserAccount object for the client being logged off. If no such user account is known, the event is dispatched via the AccountManager only.

    Unlike login, the logoff() method can be used with foreign clients. However, in order to logoff a foreign client, the client requesting the logoff must have sufficient privileges.

    Parameters

    • userID: string | null
    • Optional password: undefined | string

    Returns void

observeAccount

  • observeAccount(userID: string): void
  • Asks the server to register the current client as an observer of the user account specified by userID. If the request succeeds, Orbiter creates a UserAccount object for the account (if one does not already exist) and dispatches an AccountEvent.OBSERVE_RESULT through that object and through the AccountManager. The UserAccount object is also synchronized with the server-side state of the account, causing the UserAccount to trigger an AccountEvent.SYNCHRONIZE event. Subsequently if the specified user account's state changes, the current client is notified in the following ways:

    • Observed account logs in: current client's AccountManager and the UserAccount object trigger the AccountEvent.LOGIN event
    • Observed account logs off: current client's AccountManager and the UserAccount object trigger the AccountEvent.LOGOFF event
    • Observed account is deleted: current client's AccountManager triggers the event

    To stop observing a user account, use UserAccount.stopObserving method.

    Account observation is used when a client wishes to stay informed of the state of an arbitrary list of user accounts, as is required by applications with buddy-list systems or account administration features.

    Parameters

    • userID: string

      The userID of the account to observe.

    Returns void

removeAccount

  • removeAccount(userID: string, password: string): void
  • Removes an existing user account. The result of the account-removal attempt is returned via an AccountManagerEvent.REMOVE_ACCOUNT_RESULT event. If a user account is removed while a client is logged in as that user, that client receives an AccountEvent.LOGOFF event and is then automatically disconnected by the server.

    Parameters

    • userID: string
    • password: string

    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 a user account. The result of the remove-role attempt is returned via an AccountEvent.REMOVE_ROLE_RESULT event, which is dispatched both via the AccountManager and also via the UserAccount object for which the role-removal was requested. If no such account is known, the event is dispatched via the AccountManager.

    Parameters

    • userID: string

      The account's userID.

    • role: string

      The desired new role.

    Returns void

selfAccount

  • Returns a reference to the current client's user account, if the current client is logged in. If the current client is not logged in, returns null.

    Returns UserAccount | null

stopWatchingForAccounts

  • stopWatchingForAccounts(): void
  • Asks the server to stop watching for accounts. In response, the server no longer sends notifications when an account is added or removed.

    The result of a stopWatchingForAccounts() request is returned via AccountManagerEvent.STOP_WATCHING_FOR_ACCOUNTS_RESULT.

    Returns void

watchForAccounts

  • watchForAccounts(): void