Skip to content

VoiceWebSocket

classe · Source

Represents a Voice Connection's WebSocket.

Extends: EventEmitter

Properties

connection

connection: VoiceConnection

The Voice Connection that this WebSocket serves Source

attempts

attempts: number

How many connection attempts have been made Source

client

readonly

client: Client

The client of this voice WebSocket Source

ws

ws: WebSocket

The actual WebSocket used to connect to the Voice WebSocket Server. Source

Methods

reset

reset()

Resets the current WebSocket. Source

connect

connect()

Starts connecting to the Voice WebSocket Server. Source

send

send(data: string): Promise<string>

Sends data to the WebSocket if it is open. Parameters

NameTypeDescription
datastringThe data to send to the WebSocket

Returns: Promise<string>Source

sendPacket

async

async sendPacket(packet: Object): Promise<string>

JSON.stringify's a packet and then sends it to the WebSocket Server. Parameters

NameTypeDescription
packetObjectThe packet to send

Returns: Promise<string>Source

onOpen

onOpen()

Called whenever the WebSocket opens. Source

onMessage

onMessage(event: MessageEvent): void

Called whenever a message is received from the WebSocket. Parameters

NameTypeDescription
eventMessageEventThe message event that was received

Returns: voidSource

onClose

onClose(event: CloseEvent)

Called whenever the connection to the WebSocket server is lost. Parameters

NameTypeDescription
eventCloseEventThe WebSocket close event
Source

onError

onError(error: Error)

Called whenever an error occurs with the WebSocket. Parameters

NameTypeDescription
errorErrorThe error that occurred
Source

onPacket

onPacket(packet: Object)

Called whenever a valid packet is received from the WebSocket. Parameters

NameTypeDescription
packetObjectThe received packet
Source

setHeartbeat

setHeartbeat(interval: number)

Sets an interval at which to send a heartbeat packet to the WebSocket. Parameters

NameTypeDescription
intervalnumberThe interval at which to send a heartbeat packet
Source

clearHeartbeat

clearHeartbeat()

Clears a heartbeat interval, if one exists. Source

sendHeartbeat

sendHeartbeat()

Sends a heartbeat packet. Source

Events

ready

ready: unknown

Emitted once the voice WebSocket receives the ready packet. Parameters

NameTypeDescription
packetObjectThe received packet
Source

sessionDescription

sessionDescription: unknown

Emitted once the Voice Websocket receives a description of this voice session. Parameters

NameTypeDescription
packetObjectThe received packet
Source

startSpeaking

startSpeaking: unknown

Emitted whenever a speaking packet is received. Parameters

NameTypeDescription
dataObject
Source

startStreaming

startStreaming: unknown

Emitted whenever a streaming packet is received. Parameters

NameTypeDescription
dataObject
Source

unknownPacket

unknownPacket: unknown

Emitted when an unhandled packet is received. Parameters

NameTypeDescription
packetObject
Source

warn

warn: unknown

Emitted whenever the voice WebSocket encounters a non-fatal error. Parameters

NameTypeDescription
warnstringThe warning
Source

Unofficial software. Not affiliated with or supported by Discord.