Link Search Menu Expand Document (external link)

Birb / Websocket

Class: Websocket

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Websocket(client, domain)

Parameters

Name Type
client Birb
domain string

Overrides

BaseWebsocket.constructor

Defined in

src/classes/ws/Websocket.ts:66

Properties

buffer

Protected buffer: any

The internal erlpack buffer.

Inherited from

BaseWebsocket.buffer

Defined in

src/classes/ws/BaseWebsocket.ts:44


client

client: Birb

The Birb client.

Inherited from

BaseWebsocket.client

Defined in

src/classes/ws/BaseWebsocket.ts:24


connectedSince

connectedSince: number = 0

The time since the last connection.

Defined in

src/classes/ws/Websocket.ts:55


doNotReconnect

doNotReconnect: boolean = false

Whether or not to prevent reconnection.

Defined in

src/classes/ws/Websocket.ts:47


domain

domain: string

The websocket domain to connect to.

Inherited from

BaseWebsocket.domain

Defined in

src/classes/ws/BaseWebsocket.ts:28


encoding

encoding: string

The encoding to use.

Inherited from

BaseWebsocket.encoding

Defined in

src/classes/ws/BaseWebsocket.ts:40


expectedGuilds

expectedGuilds: string[] = []

The guild IDs we are expecting to receive.

Defined in

src/classes/ws/Websocket.ts:63


hasBeenReady

hasBeenReady: boolean = false

Whether or not the websocket has been ready before.

Defined in

src/classes/ws/Websocket.ts:59


heartbeatInterval

heartbeatInterval: undefined | number

The interval to send heartbeats.

Defined in

src/classes/ws/Websocket.ts:30


lastHeartbeat

lastHeartbeat: number = 0

The time the last heartbeat was sent.

Defined in

src/classes/ws/Websocket.ts:21


lastHeartbeatAcked

lastHeartbeatAcked: boolean = false

Whether or not the last heartbeat was acknowledged by the Discord gateway.

Defined in

src/classes/ws/Websocket.ts:26


lastResume

lastResume: number = 0

The time the last resume packet was sent.

Defined in

src/classes/ws/Websocket.ts:51


lastSequenceIdentifier

lastSequenceIdentifier: undefined | number

The last sequence identifier received from the Discord gateway.

Defined in

src/classes/ws/Websocket.ts:43


ping

ping: number = 0

The current latency (in milliseconds) between the client and the Discord gateway.

Defined in

src/classes/ws/Websocket.ts:17


resumeGatewayUrl

resumeGatewayUrl: undefined | string

The URL to use when resuming a connection.

Defined in

src/classes/ws/Websocket.ts:38


schedulerLoop

schedulerLoop: undefined | Timer

Defined in

src/classes/ws/Websocket.ts:64


sessionIdentifier

sessionIdentifier: undefined | string

The session identifier from the Discord gateway.

Defined in

src/classes/ws/Websocket.ts:34


socket

socket: undefined | WebSocket

The websocket instance from the ws package.

Defined in

src/classes/ws/Websocket.ts:12


status

status: GatewayStatus = Status.IDLE

The current websocket status.

Inherited from

BaseWebsocket.status

Defined in

src/classes/ws/BaseWebsocket.ts:36


url

url: URL

The URL to connect to.

Inherited from

BaseWebsocket.url

Defined in

src/classes/ws/BaseWebsocket.ts:32

Methods

close

close(code?): void

Close the websocket.

Parameters

Name Type Description
code? number The close code.

Returns

void

Voids once completed.

Defined in

src/classes/ws/Websocket.ts:509


connect

connect(): void

Returns

void

Defined in

src/classes/ws/Websocket.ts:70


generateURL

generateURL(): URL

Returns

URL

Inherited from

BaseWebsocket.generateURL

Defined in

src/classes/ws/BaseWebsocket.ts:151


heartbeat

heartbeat(): Promise<void>

Send a heartbeat to the gateway.

Returns

Promise<void>

Voids once sent.

Defined in

src/classes/ws/Websocket.ts:476


init

Protected init(): void

Initializes ZLib if supported.

Returns

void

Voids once ZLib is initialized.

Inherited from

BaseWebsocket.init

Defined in

src/classes/ws/BaseWebsocket.ts:142


isClosed

isClosed(): boolean

Check if the websocket is closed.

Returns

boolean

Whether or not the websocket is closed.

Defined in

src/classes/ws/Websocket.ts:568


isConnected

isConnected(): boolean

Check if the websocket is connected.

Returns

boolean

Whether or not the websocket is connected.

Defined in

src/classes/ws/Websocket.ts:545


isConnecting

isConnecting(): boolean

Check if the websocket is connecting.

Returns

boolean

Whether or not the websocket is connecting.

Defined in

src/classes/ws/Websocket.ts:559


pack

Protected pack(data): any

Packs data for sending to Discord. If the encoding is set to etf, this method will use the zlib-sync (npm install zlib-sync) library to pack its etf data. Otherwise, parses the JSON data to a string.

Parameters

Name Type Description
data any The data to pack.

Returns

any

Hopefully, the data’s packed form.

Inherited from

BaseWebsocket.pack

Defined in

src/classes/ws/BaseWebsocket.ts:132


preventReconnect

preventReconnect(value?): void

Prevent reconnection.

Parameters

Name Type
value? boolean

Returns

void

Voids once completed.

Defined in

src/classes/ws/Websocket.ts:578


processPacket

Protected processPacket(data): any

Attempts to process a packet by using ZLib to let Discord send packets in chunks. If ZLib is not yet installed (npm install zlib-sync), this method will just pass the data through for unpacking (this.unpack()).

Parameters

Name Type Description
data any The packet’s data.

Returns

any

Hopefully, the packet’s JSON form.

Inherited from

BaseWebsocket.processPacket

Defined in

src/classes/ws/BaseWebsocket.ts:63


reconnect

reconnect(): void

Reconnect to the gateway.

Returns

void

Voids once completed.

Defined in

src/classes/ws/Websocket.ts:89


send

send(data): void

Send a packet to the gateway.

Parameters

Name Type Description
data Object The data to send.

Returns

void

Voids once sent.

Defined in

src/classes/ws/Websocket.ts:440


setSessionIdentifier

setSessionIdentifier(sessionIdentifier): void

Set the websocket’s session identifier.

Parameters

Name Type Description
sessionIdentifier string The session identifier to set.

Returns

void

Voids once completed.

Defined in

src/classes/ws/Websocket.ts:598


setStatus

setStatus(status): void

Set the websocket’s status.

Parameters

Name Type Description
status GatewayStatus The status to set.

Returns

void

Voids once completed.

Defined in

src/classes/ws/Websocket.ts:588


terminate

terminate(): void

Terminate the websocket. Does not notify the gateway that you’ve disconnected. Should only be used when the gateway won’t respond (e.g. timeouts).

Returns

void

Voids once completed.

Defined in

src/classes/ws/Websocket.ts:530


unpack

Protected unpack(data, type?): any

Unpacks a packet using the current encoding. If the encoding is set to etf, this method will use the zlib-sync (npm install zlib-sync) library to unpack its etf data. Otherwise, parses the data to normal JSON.

Parameters

Name Type Description
data any The packet’s data.
type? string The packet’s encoding.

Returns

any

Hopefully, the packet’s JSON form.

Inherited from

BaseWebsocket.unpack

Defined in

src/classes/ws/BaseWebsocket.ts:109