API Reference
    Preparing search index...

    Class WebSocketDriver

    WebSocket-based signaling driver with auto-reconnection and ping/pong support. It maintains a map of namespaces to sets of handlers, and automatically re-subscribes to namespaces after reconnection. It also queues messages when the socket is not opened, and flushes them upon connection.

    const driver = new WebSocketDriver({ url: 'wss://localhost:8443/ws' });
    

    Hierarchy

    • Map
      • WebSocketDriver

    Implements

    Index

    Constructors

    • Creates a new WebSocketDriver instance with the specified options.

      Parameters

      • Optionaloptions: {
            pingInterval?: number;
            pingTimeout?: number;
            protocols?: string | string[];
            queueLimit?: number;
            randomizationFactor?: number;
            reconnection?: boolean;
            reconnectionAttempts?: number;
            reconnectionDelay?: number;
            reconnectionDelayMax?: number;
            url?: string;
        }

        Configuration options for the driver.

        • OptionalpingInterval?: number

          Interval for sending ping messages in ms (default: 30000).

        • OptionalpingTimeout?: number

          Timeout for receiving pong responses in ms (default: 10000).

        • Optionalprotocols?: string | string[]

          Optional subprotocols for the WebSocket connection.

        • OptionalqueueLimit?: number

          Maximum number of queued messages when socket is not opened (default: 100).

        • OptionalrandomizationFactor?: number

          Randomization factor for reconnection delay (default: 0.5).

        • Optionalreconnection?: boolean

          Whether to enable auto-reconnection (default: true).

        • OptionalreconnectionAttempts?: number

          Maximum number of reconnection attempts (default: Infinity).

        • OptionalreconnectionDelay?: number

          Initial delay for reconnection attempts in ms (default: 5000).

        • OptionalreconnectionDelayMax?: number

          Maximum delay for reconnection attempts in ms (default: 60000).

        • Optionalurl?: string

          The WebSocket server URL (default: '/ws').

      Returns WebSocketDriver

    Properties

    "[toStringTag]": string
    size: number

    the number of elements in the Map.

    "[species]": MapConstructor

    Accessors

    • get opened(): boolean

      Indicates whether the WebSocket connection is currently open.

      Returns boolean

    Methods

    • Returns an iterable of entries in the map.

      Returns MapIterator<[any, any]>

    • Returns void

    • Closes the WebSocket connection and clears all handlers and queued messages.

      Returns void

    • Parameters

      • key: any

      Returns boolean

      true if an element in the Map existed and has been removed, or false if the element does not exist.

    • Publish a signaling message to a namespace.

      Parameters

      • namespace: string[]

        Target namespace segments.

      • message: any

      Returns void

    • Returns an iterable of key, value pairs for every entry in the map.

      Returns MapIterator<[any, any]>

    • Executes a provided function once per each key/value pair in the Map, in insertion order.

      Parameters

      • callbackfn: (value: any, key: any, map: Map<any, any>) => void
      • OptionalthisArg: any

      Returns void

    • Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.

      Parameters

      • key: any

      Returns any

      Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

    • Parameters

      • key: any

      Returns boolean

      boolean indicating whether an element with the specified key exists or not.

    • Returns an iterable of keys in the map

      Returns MapIterator<any>

    • Unsubscribe a previously registered namespace handler.

      Parameters

      • namespace: string[]

        Namespace segments used for message routing.

      • handler: (data: any) => void

        Handler reference originally passed to on.

      Returns void

    • Subscribe to signaling messages in a namespace.

      Parameters

      • namespace: string[]

        Namespace segments used for message routing.

      • handler: (data: any) => void

        Callback invoked with message payload.

      Returns void

    • Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.

      Parameters

      • key: any
      • value: any

      Returns this

    • Returns an iterable of values in the map

      Returns MapIterator<any>

    • Groups members of an iterable according to the return value of the passed callback.

      Type Parameters

      • K
      • T

      Parameters

      • items: Iterable<T>

        An iterable.

      • keySelector: (item: T, index: number) => K

        A callback which will be invoked for each item in items.

      Returns Map<K, T[]>