Connection
Coordinates a full Discord voice connection. Owns four sub-components:
webSocket- WebSocket lifecycle and heartbeatingudp- UDP socket, keepalive, and RTP audio send/receivertp- RTP encryption and sequence/timestamp/nonce countersdave- DAVE E2EE MLS session and per-user key rotation
Connection handles voice signalling (Identify, Resume, SelectProtocol, Speaking), opcode dispatch, jitter buffering per SSRC, and gateway shard integration.
Consumer-facing events: onReady, onSpeaking, onClientConnect, onClientDisconnect,
onDaveEpochTransition, onRawAudioFrame, onAudioFrame.
Summary
Properties
Connection.webSocket :: voiceWebsocket.WebSocketTransportConnection.udp :: voiceUdp.UdpTransportConnection.rtp :: voiceRtpCrypto.RtpCryptoConnection.dave :: voiceDaveManager.DaveManagerConnection.jitters :: { [number]: voiceJitter.Jitter }Connection.shard :: websocket.ShardConnection.guildId :: stringConnection.channelId :: stringConnection.userId :: stringConnection.sessionId :: stringConnection.token :: secret.Secret<string>Connection.endpoint :: stringConnection.onConnected :: emitter.Emitter<()>Connection.onDisconnected :: emitter.Emitter<number?, boolean?>Connection.onReady :: emitter.Emitter<()>Connection.onHeartbeat :: emitter.Emitter<number?>Connection.onRawMessage :: emitter.Emitter<apiTypes.Payload<unknown>>Connection.onSpeaking :: emitter.Emitter<{ userId: string, ssrc: number, speaking: number }>Connection.onClientConnect :: emitter.Emitter<{ userId: string }>Connection.onClientDisconnect :: emitter.Emitter<{ userId: string }>Connection.onDaveEpochTransition :: emitter.Emitter<number>Connection.onRawAudioFrame :: emitter.Emitter<{ userId: string?, ssrc: number, frame: buffer }>Connection.onAudioFrame :: emitter.Emitter<{ userId: string?, ssrc: number, frame: buffer }>Connection.logger :: logger.LoggerProperties
Section titled “Properties”webSocket
Section titled “webSocket”jitters
Section titled “jitters”{ [number]: voiceJitter.Jitter } }
guildId
Section titled “guildId”channelId
Section titled “channelId”userId
Section titled “userId”sessionId
Section titled “sessionId”endpoint
Section titled “endpoint”onConnected
Section titled “onConnected”onDisconnected
Section titled “onDisconnected”onReady
Section titled “onReady”onHeartbeat
Section titled “onHeartbeat”onRawMessage
Section titled “onRawMessage”onSpeaking
Section titled “onSpeaking”onClientConnect
Section titled “onClientConnect”onClientDisconnect
Section titled “onClientDisconnect”onDaveEpochTransition
Section titled “onDaveEpochTransition”onRawAudioFrame
Section titled “onRawAudioFrame”Fires for each decoded audio frame before Opus decoding. frame is the fully decrypted
RTP packet (12-byte RTP header + Opus payload) with all encryption layers (DAVE E2EE and
RTP encryption) already removed. Wire-level ciphertext is never exposed.
onAudioFrame
Section titled “onAudioFrame”logger
Section titled “logger”Methods
Section titled “Methods”sendAsync
Section titled “sendAsync”Connection : sendAsync ( data ) -> ()
Sends a raw message to the voice gateway WebSocket.
Parameters
| data: string | buffer |
connectAsync
Section titled “connectAsync”Connection : connectAsync ( ) -> ()
Opens the voice WebSocket connection. Session state is preserved when resuming.
forceClose
Section titled “forceClose”Connection : forceClose ( code ) -> ()
Closes the voice WebSocket connection with an optional close code.
Parameters
| code: number? |
forceClose
Section titled “forceClose”Connection : forceClose ( code ) -> ()
Synchronously closes the voice connection and cleans up all session state. Safe to call from a signal handler or any context where yielding is not permitted.
Parameters
| code: number? |
reconnectAsync
Section titled “reconnectAsync”Connection : reconnectAsync ( ) -> ()
Disconnects and reconnects the voice WebSocket. Concurrent reconnect attempts are rejected.
requestVoiceAsync
Section titled “requestVoiceAsync”Connection : requestVoiceAsync ( ) -> ()
Sends a VOICE_STATE_UPDATE to the gateway shard to request a voice server for this channel.
setSpeakingAsync
Section titled “setSpeakingAsync”Connection : setSpeakingAsync ( speakingFlags ) -> ()
Sets the bot’s speaking state. Pass a bitmask of speaking flags (Microphone = 1, Soundshare = 2, Priority = 4).
Parameters
| speakingFlags: number |
sendOpusAsync
Section titled “sendOpusAsync”Connection : sendOpusAsync ( audioFrame ) -> ()
Encrypts and sends a raw Opus audio frame over UDP.
Parameters
| audioFrame: buffer |