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

session

session: Session | null

Session instance

type

{Session|null}

memberof

State

Methods

broadcast

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

    memberof

    State

    Type parameters

    • T

    Parameters

    • eventName: string | number
    • data: T

    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

emit

  • emit<T>(actorId: string | string[], eventName: string | number, data: T): 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

    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

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