Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • IState

Index

Properties

actorId

actorId: string | null

Actor ID

Depending on how the state object was created, the actor ID may hold different meaning; however, it will in most cases hold the session ID of the user currently executing the user command. This will only apply to users authenticated through the auth module.

type

{string}

memberof

IState

archivist

archivist: Archivist

Archivist instance

When a state is received through a user command, use this archvist instance to make your data transactions. The state will automatically call distribute upon a successful user command execution.

type

{Archivist}

memberof

State

Optional data

data: Object

State metadata

This data can be used to carry data around through the execution path.

session

session: Session | null

Session instance

type

{Session|null}

memberof

State

Methods

broadcast

  • broadcast<T>(eventName: string | number, data: T, configuration?: IStateEmitConfig): void
  • Broadcast an event to all connected users

    memberof

    State

    Type parameters

    • T

    Parameters

    Returns void

canAccess

  • canAccess(acl: any): boolean
  • Verify the current user's credentials

    memberof

    State

    Parameters

    • acl: any

    Returns boolean

clearTimeout

  • clearTimeout(): void
  • Clear a given state's timeout

    This will do nothing if a timeout is not set on the state

    memberof

    State

    Returns void

close

  • close(callback: function): void
  • Close this state object

    Note: You should never really have to use this method, it is only documented for informational purposes.

    This will trigger the same thing as distribute, but will return the response value set on the state and the events to be returned directly to the actor this state refers to.

    memberof

    State

    Parameters

    • callback: function
        • (error: Error | null, data: object): void
        • Parameters

          • error: Error | null
          • data: object
            • events: any
            • response: any

          Returns void

    Returns void

distribute

  • distribute(callback: function): void
  • Distribute both events and archivist operations currently stacked on this state object.

    memberof

    State

    Parameters

    • callback: function
        • (error?: Error): void
        • Parameters

          • Optional error: Error

          Returns void

    Returns void

distributeEvents

  • distributeEvents(callback: function): void
  • Distribute all events currently stacked on this state object.

    If you wish to also distribute archivist mutations stacked on this state, please have a look at the distribute method instead.

    memberof

    State

    Parameters

    • callback: function
        • (error?: Error): void
        • Parameters

          • Optional error: Error

          Returns void

    Returns void

emit

  • emit<T>(actorId: string | string[], eventName: string | number, data: T, configuration?: IStateEmitConfig): void
  • Send an event to the user

    Note that the event will be blackholed if an user with a given actorId is not currently connected.

    memberof

    State

    Type parameters

    • T

    Parameters

    • actorId: string | string[]
    • eventName: string | number
    • data: T
    • Optional configuration: IStateEmitConfig

    Returns void

error

  • error(code: string | number, error: Error, callback: Function): void
  • Return an error to the user

    This will generally be called in synchronouse user commands to specify that an error has occured, and that no response data is to be expected.

    Note that asynchronous user commands as defined in https://mage.github.io/mage/#using-async-await-node-7-6 do not require you to call state.error; instead, you can simply throw an Error. If the Error instance has a code attribute, the code will then also be returned as part of the response to the end-user.

    memberof

    State

    Parameters

    • code: string | number
    • error: Error
    • callback: Function

    Returns void

findActors

  • findActors(actorIds: string[], callback: function): void
  • Parse a list of actorIds, and verify who is online

    Parameters

    • actorIds: string[]
    • callback: function
        • (error: Error | null, actors: object): void
        • Parameters

          • error: Error | null
          • actors: object
            • offline: string[]
            • online: string[]

          Returns void

    Returns void

registerSession

  • registerSession(session: any): void
  • Register a session on the user

    memberof

    State

    Parameters

    • session: any

    Returns void

respond

  • respond(data: any): void
  • Reply to the user

    This will generally be called in synchronouse user commands to specify what value to return to the end-user.

    Note that asynchronous user commands as defined in https://mage.github.io/mage/#using-async-await-node-7-6 do not require you to call state.respond; instead, simply return the data you wish to send to the end-user.

    memberof

    State

    Parameters

    • data: any

    Returns void

setTimeout

  • setTimeout(timeout: number): void
  • Define a timeout on the state

    Once the timeout is reached, the state will automatically report an error to the end-user.

    Note that you do not have to call clearTimeout manually when receiving a state in a user command; this will be done automatically for you.

    memberof

    State

    Parameters

    • timeout: number

    Returns void

unregisterSession

  • unregisterSession(): void
  • Forget the current session for the current user

    memberof

    State

    Returns void