Appearance
VoiceConnection
Package: @erinjs/voice
Voice connection using Discord's UDP-based protocol. Emits ready, error, disconnect.
Constructor
| Name | Type | Optional | Description |
|---|---|---|---|
client | Client | No | |
channel | VoiceChannel | No | |
userId | string | No |
Properties
| Name | Type | Readonly | Optional | Description |
|---|---|---|---|---|
audioPacketQueue | Buffer<ArrayBufferLike>[] | No | No | |
channel | VoiceChannel | Yes | No | |
client | Client | Yes | No | |
currentStream | { destroy?: () => void; } | null | No | No | |
guildId | string | Yes | No | |
heartbeatInterval | NodeJS.Timeout | null | No | No | |
pacingInterval | NodeJS.Timeout | null | No | No | |
playing | boolean | Yes | No | Whether audio is currently playing. |
remoteUdpAddress | string | No | No | |
remoteUdpPort | number | No | No | |
secretKey | Uint8Array<ArrayBufferLike> | null | No | No | |
sequence | number | No | No | |
sessionId | string | null | Yes | No | Discord voice session ID. |
ssrc | number | No | No | |
timestamp | number | No | No | |
udpSocket | dgram.Socket | null | No | No | |
voiceWs | VoiceWebSocket | null | No | No |
Methods
connect() async
Called when we have both server update and state update.
Returns: Promise<void>
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
server | GatewayVoiceServerUpdateDispatchData | No | |
state | GatewayVoiceStateUpdateDispatchData | No |
destroy()
Disconnect and remove all listeners.
Returns: void
Parameters:
None
disconnect()
Disconnect from voice (closes WebSocket and UDP).
Returns: void
Parameters:
None
getWebSocketConstructor() async
Returns: Promise<new (url: string) => VoiceWebSocket>
Parameters:
None
play() async
Play a direct WebM/Opus URL or stream. Fetches the URL (if string), demuxes with prism-media WebmDemuxer, and sends Opus packets to the voice connection. No FFmpeg or encoding; input must be WebM with Opus.
Returns: Promise<void>
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
urlOrStream | string | NodeJS.ReadableStream | No |
playOpus()
Play a stream of raw Opus packets Uses the same queue and 20ms pacing as play(). Use this for local files (MP3 → PCM → Opus) or other Opus sources.
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
stream | NodeJS.ReadableStream | No |
sendAudioFrame()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
opusPayload | Buffer<ArrayBufferLike> | No |
sendVoiceOp()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
op | number | No | |
d | unknown | No |
setupUDP()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
remoteAddress | string | No | |
remotePort | number | No | |
onReady | () => void | No |
stop()
Stop playback and clear the queue.
Returns: void
Parameters:
None