Interface Context

Represents the context for a WebSocket connection, extending the capabilities of a GroupEmitter. Provides methods for managing group memberships and emitting events to groups.

interface Context {
    isAdmin?: boolean;
    userId?: string;
    userName?: string;
    addToGroup(group: string): void;
    emit(method: string, ...params: any): void;
    emitToGroup(group: string, method: string, ...params: any): void;
    iterateGroup(group: string, cb: (context: Context) => void): void;
    removeFromGroup(group: string): void;
}

Hierarchy (View Summary)

Properties

isAdmin?: boolean

Indicates whether the user is an admin.

userId?: string

The optional user ID associated with this context.

userName?: string

The optional user name associated with this context.

Methods

  • Adds the websocket from this context to the specified group.

    Parameters

    • group: string

      The name of the group to add the context to.

    Returns void

  • Emits an event with the specified parameters to the caller.

    Parameters

    • method: string

      The method name to call.

    • ...params: any

      The parameters to pass with the method call.

    Returns void

  • Emits an event to a specified group.

    Parameters

    • group: string

      The name of the group to emit the event to.

    • method: string

      The method name to be called on the group.

    • ...params: any

      Additional parameters to be passed to the method.

    Returns void

  • Iterates over a specified group and executes a callback function for each context.

    Parameters

    • group: string

      The name of the group to iterate over.

    • cb: (context: Context) => void

      The callback function to be executed for each context.

    Returns void

  • Removes the websocket from this context from the specified group.

    Parameters

    • group: string

      The name of the group to remove the context from.

    Returns void