Skip to main content
Branch: Development

WebSocketClient

Hierarchy

  • BaseObject
    • WebSocketClient

Index

Constructors

constructor

  • new WebSocketClient(url: string): WebSocketClient

Properties

publicautoReconnect

autoReconnect: boolean

publicreadonlyid

id: number

publicreadonlyisRemote

isRemote: boolean

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

publicperMessageDeflate

perMessageDeflate: boolean

publicpingInterval

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.

publicreadonlyreadyState

readyState: WebSocketReadyState

publicreadonlyrefCount

refCount: number

Returns the ref count of the entity.

Remarks

It’s only available in debug-mode.

publicreadonlyremoteID

remoteID: number

The serverside id of this entity.

publicreadonlytype

type: BaseObjectType

Type of the object.

publicurl

url: string

publicreadonlyvalid

valid: boolean

Object usability.

Returns

False if object is no longer usable.

Methods

publicaddSubProtocol

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

publicdeleteMeta

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

publicdestroy

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

publicgetEventListeners

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

publicgetMeta

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

    • K: string

publicgetMetaDataKeys

  • getMetaDataKeys(): readonly string[]

publicgetSubProtocols

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

publicgetSyncedMeta

  • getSyncedMeta<K>(key: Exclude<K, never>): unknown
  • getSyncedMeta<K>(key: K): undefined | ICustomBaseObjectSyncedMeta[K]
  • getSyncedMeta<V>(key: string): undefined | V
  • Gets a value using the specified key.


    Type parameters

    • K: string

publicgetSyncedMetaKeys

  • getSyncedMetaKeys(): readonly string[]

publichasMeta

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

publichasSyncedMeta

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

publicoff

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

publicon

  • 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

publicsend

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

publicsetExtraHeader

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

publicsetMeta

  • setMeta<K>(key: K, value: InterfaceValueByKey<ICustomBaseObjectMeta, K, unknown, void>): void
  • setMeta<K>(key: K, value: ICustomBaseObjectMeta[K]): void
  • setMeta<V, K>(key: K, value: InterfaceValueByKey<ICustomBaseObjectMeta, K, V, void>): void
  • Type parameters

    • K: string

publicstart

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

publicstop

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

publicstaticgetByID

  • getByID(id: number): null | WebSocketClient
  • Retrieves the websocketclient from the pool.

publicstaticgetByRemoteID

  • getByRemoteID(type: BaseObjectType, id: number): null | BaseObject