Class EventClient<T>

Simple wrapper around the Revolt websocket service.

Type Parameters

  • T extends AvailableProtocols

Hierarchy

  • EventEmitter<Events<T, EventProtocol<T>>>
    • EventClient

Constructors

  • Create a new event client.

    Type Parameters

    • T extends 1

    Parameters

    • protocolVersion: T

      Target protocol version

    • transportFormat: "json" = "json"

      Communication format

    • Optional options: Partial<EventClientOptions>

      Configuration options

    Returns EventClient<T>

Properties

#connectTimeoutReference: undefined | number
#heartbeatIntervalReference: undefined | number
#lastError: undefined | {
    data: any;
    type: "socket";
} | {
    data: Object;
    type: "revolt";
}

Type declaration

  • data: any
  • type: "socket"

Type declaration

  • data: Object
  • type: "revolt"
#pongTimeoutReference: undefined | number
#protocolVersion: T
#setPing: Setter<number>
#setStateSetter: Setter<ConnectionState>
#socket: undefined | WebSocket
#transportFormat: "json" | "msgpack"
options: EventClientOptions
ping: Accessor<number>
state: Accessor<ConnectionState>
prefixed: string | boolean

Accessors

  • get lastError(): undefined | {
        data: any;
        type: "socket";
    } | {
        data: Object;
        type: "revolt";
    }
  • Last error encountered by events client

    Returns undefined | {
        data: any;
        type: "socket";
    } | {
        data: Object;
        type: "revolt";
    }

Methods

  • Type Parameters

    • T extends keyof Events<T, EventProtocol<T>>

    Parameters

    • event: T
    • fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<Events<T, EventProtocol<T>>>[Extract<T, keyof Events<T, EventProtocol<T>>>]

          Returns void

    • Optional context: any

    Returns EventClient<T>

  • Connect to the websocket service.

    Parameters

    • uri: string

      WebSocket URI

    • token: string

      Authentication token

    Returns void

  • Calls each of the listeners registered for a given event.

    Type Parameters

    • T extends keyof Events<T, EventProtocol<T>>

    Parameters

    • event: T
    • Rest ...args: ArgumentMap<Events<T, EventProtocol<T>>>[Extract<T, keyof Events<T, EventProtocol<T>>>]

    Returns boolean

  • Return an array listing the events for which the emitter has registered listeners.

    Returns (keyof Events<T, EventProtocol<T>>)[]

  • Handle events intended for client before passing them along.

    Parameters

    • event: EventProtocol<T>["server"]

      Event

    Returns void

  • Return the number of listeners listening to a given event.

    Parameters

    • event: keyof Events<T, EventProtocol<T>>

    Returns number

  • Return the listeners registered for a given event.

    Type Parameters

    • T extends keyof Events<T, EventProtocol<T>>

    Parameters

    • event: T

    Returns ((...args) => void)[]

  • Type Parameters

    • T extends keyof Events<T, EventProtocol<T>>

    Parameters

    • event: T
    • Optional fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<Events<T, EventProtocol<T>>>[Extract<T, keyof Events<T, EventProtocol<T>>>]

          Returns void

    • Optional context: any
    • Optional once: boolean

    Returns EventClient<T>

  • Add a listener for a given event.

    Type Parameters

    • T extends keyof Events<T, EventProtocol<T>>

    Parameters

    • event: T
    • fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<Events<T, EventProtocol<T>>>[Extract<T, keyof Events<T, EventProtocol<T>>>]

          Returns void

    • Optional context: any

    Returns EventClient<T>

  • Add a one-time listener for a given event.

    Type Parameters

    • T extends keyof Events<T, EventProtocol<T>>

    Parameters

    • event: T
    • fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<Events<T, EventProtocol<T>>>[Extract<T, keyof Events<T, EventProtocol<T>>>]

          Returns void

    • Optional context: any

    Returns EventClient<T>

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: keyof Events<T, EventProtocol<T>>

    Returns EventClient<T>

  • Remove the listeners of a given event.

    Type Parameters

    • T extends keyof Events<T, EventProtocol<T>>

    Parameters

    • event: T
    • Optional fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<Events<T, EventProtocol<T>>>[Extract<T, keyof Events<T, EventProtocol<T>>>]

          Returns void

    • Optional context: any
    • Optional once: boolean

    Returns EventClient<T>

  • Send an event to the server.

    Parameters

    • event: EventProtocol<T>["client"]

      Event

    Returns void

Generated using TypeDoc