Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WebSocketClient

Hierarchy

Index

Constructors

constructor

Properties

autoReconnect

autoReconnect: boolean

Readonly id

id: number

Readonly isRemote

isRemote: boolean

Whether this entity was created clientside or serverside. (Clientside = false, Serverside = true).

perMessageDeflate

perMessageDeflate: boolean

pingInterval

pingInterval: number

Optional heartbeat, sent every x seconds when there isn't any traffic.

remarks

This makes sure, that load balancers do not kill an idle connection.

Readonly readyState

Readonly refCount

refCount: number

Returns the ref count of the entity.

remarks

It's only available in debug-mode.

Readonly remoteID

remoteID: number

The serverside id of this entity.

Readonly type

Type of the object.

url

url: string

Readonly valid

valid: boolean

Object usability.

returns

False if object is no longer usable.

Methods

addSubProtocol

  • addSubProtocol(protocol: string): void
  • Adds a sub protocol to the websocket.

    Parameters

    • protocol: string

      Name of the protocol.

    Returns void

deleteMeta

  • deleteMeta(key: string): void
  • deleteMeta<K>(key: K): void

destroy

  • destroy(): void
  • Removes the object from the world.

    Returns void

getEventListeners

  • getEventListeners(eventName: string | null): readonly ((...args: any[]) => void)[]
  • Gets all the listeners for the specified websocket event.

    Parameters

    • eventName: string | null

      Name of the event.

    Returns readonly ((...args: any[]) => void)[]

    Array of listener functions for that event.

getMeta

  • getMeta<K>(key: Exclude<K, keyof ICustomBaseObjectMeta>): unknown
  • getMeta<K>(key: K): ICustomBaseObjectMeta[K] | undefined
  • getMeta<V>(key: string): V | undefined

getMetaDataKeys

  • getMetaDataKeys(): readonly string[]

getSubProtocols

  • getSubProtocols(): readonly string[]
  • Gets all added sub protocols.

    Returns readonly string[]

getSyncedMeta

  • getSyncedMeta<K>(key: Exclude<K, keyof ICustomBaseObjectSyncedMeta>): unknown
  • getSyncedMeta<K>(key: K): ICustomBaseObjectSyncedMeta[K] | undefined
  • getSyncedMeta<V>(key: string): V | undefined

getSyncedMetaKeys

  • getSyncedMetaKeys(): readonly string[]

hasMeta

  • hasMeta(key: string): boolean
  • hasMeta<K>(key: K): boolean

hasSyncedMeta

  • hasSyncedMeta(key: string): boolean
  • hasSyncedMeta<K>(key: K): boolean
  • Determines whether contains the specified key.

    Parameters

    • key: string

      The key of the value to locate.

    Returns boolean

    True if the meta table contains any data at the specified key or False if not

  • Type parameters

    Parameters

    • key: K

    Returns boolean

off

  • off(eventName: string, listener: (...args: any[]) => void): void
  • Parameters

    • eventName: string
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

on

  • on(eventName: "open", listener: () => void): void
  • on(eventName: "close", listener: (code: number, reason: string) => void): void
  • on(eventName: "message", listener: (message: string) => void): void
  • on(eventName: "error", listener: (error: string) => void): void
  • Parameters

    • eventName: "open"
    • listener: () => void
        • (): void
        • Returns void

    Returns void

  • Parameters

    • eventName: "close"
    • listener: (code: number, reason: string) => void
        • (code: number, reason: string): void
        • Parameters

          • code: number
          • reason: string

          Returns void

    Returns void

  • Parameters

    • eventName: "message"
    • listener: (message: string) => void
        • (message: string): void
        • Parameters

          • message: string

          Returns void

    Returns void

  • Parameters

    • eventName: "error"
    • listener: (error: string) => void
        • (error: string): void
        • Parameters

          • error: string

          Returns void

    Returns void

send

  • send(message: string | ArrayBuffer | ArrayBufferView): boolean
  • Sends the specified message to the websocket server.

    Parameters

    • message: string | ArrayBuffer | ArrayBufferView

      The message to send.

    Returns boolean

    Whether sending the message was successful.

setExtraHeader

  • setExtraHeader(header: string, value: string): void
  • Sets the specified header to the specified value.

    Parameters

    • header: string

      Header name.

    • value: string

      Header value.

    Returns void

setMeta

  • setMeta<K>(key: K, value: shared.InterfaceValueByKey<ICustomBaseObjectMeta, K>): void
  • setMeta<K>(key: K, value: ICustomBaseObjectMeta[K]): void
  • setMeta<V, K>(key: K, value: shared.InterfaceValueByKey<ICustomBaseObjectMeta, K, V>): void

start

  • start(): void
  • Starts the websocket connection.

    Returns void

stop

  • stop(): void
  • Stops the websocket connection.

    Returns void

Static getByID

  • Retrieves the websocketclient from the pool.

    Parameters

    • id: number

      The id of the websocketclient.

    Returns WebSocketClient | null

    Entity if it was found, otherwise null.

Static getByRemoteID