Skip to content

WebSocketTransport

Manages the WebSocket connection to the Discord voice gateway: socket lifecycle, binary and JSON message framing, and heartbeating. Detects zombified connections (unacknowledged heartbeat) and notifies the owner via the onZombified callback.

WebSocketTransport.socketActive  :: boolean
WebSocketTransport.socketReconnecting  :: boolean
WebSocketTransport.socketDisconnecting  :: boolean
WebSocketTransport.isResuming  :: boolean
WebSocketTransport.socketInstance  :: any?
WebSocketTransport.socketThread  :: thread?
WebSocketTransport.heartbeatInterval  :: number?
WebSocketTransport.heartbeatThread  :: thread?
WebSocketTransport.heartbeatAcknowledged  :: boolean
WebSocketTransport.heartbeatClockTime  :: number?
WebSocketTransport.heartbeatPing  :: number?
WebSocketTransport.sequenceAcknowledgement  :: number
WebSocketTransport.onConnected  :: (() -> ())?
WebSocketTransport.onDisconnected  :: ((code: number?, closedBySelf: boolean?) -> ())?
WebSocketTransport.onMessage  :: ((payload: any) -> ())?
WebSocketTransport.onZombified  :: (() -> ())?
WebSocketTransport.logger  :: Logger
WebSocketTransport : sendAsync ( data )  -> ()

Sends a raw message over the voice WebSocket.

Parameters

data: string | buffer
WebSocketTransport : _handleMessage ( message )  -> ()

Decodes an incoming voice gateway message and dispatches it to onMessage. Binary frames are unwrapped from the voice binary framing format; JSON payloads are decoded directly.

Parameters

message: string
WebSocketTransport : heartbeatAsync ( requested )  -> ()

Sends a voice heartbeat. If the previous heartbeat was never acknowledged the connection is marked as zombified and onZombified is fired instead.

Parameters

requested: boolean?
WebSocketTransport : heartbeatIn ( milliseconds )  -> ()

Schedules the next heartbeat to fire after the given number of milliseconds, cancelling any pending heartbeat.

Parameters

milliseconds: number
WebSocketTransport : _openSocket ( url )  -> ()

Opens the WebSocket to the given URL, starts the receive loop, and fires onConnected.

Parameters

url: string
WebSocketTransport : forceClose ( code )  -> ()

Synchronously closes the voice WebSocket and kills all associated threads. Safe to call from a signal handler or any context where yielding is not permitted.

Parameters

code: number?
WebSocketTransport . new ( loggerInstance )  -> WebSocketTransport

Responsible for constructing this class.

Parameters

loggerInstance: Logger

Returns

WebSocketTransport