VoiceWebSocket
classe · Source
Represents a Voice Connection's WebSocket.
Extends: EventEmitter
Properties
connection
The Voice Connection that this WebSocket serves Source
attempts
How many connection attempts have been made Source
client
The client of this voice WebSocket Source
ws
The actual WebSocket used to connect to the Voice WebSocket Server. Source
Methods
reset
Resets the current WebSocket. Source
connect
Starts connecting to the Voice WebSocket Server. Source
send
Sends data to the WebSocket if it is open. Parameters
| Name | Type | Description |
|---|---|---|
data | string | The data to send to the WebSocket |
Returns: Promise<string>Source
sendPacket
JSON.stringify's a packet and then sends it to the WebSocket Server. Parameters
| Name | Type | Description |
|---|---|---|
packet | Object | The packet to send |
Returns: Promise<string>Source
onOpen
Called whenever the WebSocket opens. Source
onMessage
Called whenever a message is received from the WebSocket. Parameters
| Name | Type | Description |
|---|---|---|
event | MessageEvent | The message event that was received |
Returns: voidSource
onClose
Called whenever the connection to the WebSocket server is lost. Parameters
| Name | Type | Description |
|---|---|---|
event | CloseEvent | The WebSocket close event |
| Source |
onError
Called whenever an error occurs with the WebSocket. Parameters
| Name | Type | Description |
|---|---|---|
error | Error | The error that occurred |
| Source |
onPacket
Called whenever a valid packet is received from the WebSocket. Parameters
| Name | Type | Description |
|---|---|---|
packet | Object | The received packet |
| Source |
setHeartbeat
Sets an interval at which to send a heartbeat packet to the WebSocket. Parameters
| Name | Type | Description |
|---|---|---|
interval | number | The interval at which to send a heartbeat packet |
| Source |
clearHeartbeat
Clears a heartbeat interval, if one exists. Source
sendHeartbeat
Sends a heartbeat packet. Source
Events
ready
Emitted once the voice WebSocket receives the ready packet. Parameters
| Name | Type | Description |
|---|---|---|
packet | Object | The received packet |
| Source |
sessionDescription
Emitted once the Voice Websocket receives a description of this voice session. Parameters
| Name | Type | Description |
|---|---|---|
packet | Object | The received packet |
| Source |
startSpeaking
Emitted whenever a speaking packet is received. Parameters
| Name | Type | Description |
|---|---|---|
data | Object | |
| Source |
startStreaming
Emitted whenever a streaming packet is received. Parameters
| Name | Type | Description |
|---|---|---|
data | Object | |
| Source |
unknownPacket
Emitted when an unhandled packet is received. Parameters
| Name | Type | Description |
|---|---|---|
packet | Object | |
| Source |
warn
Emitted whenever the voice WebSocket encounters a non-fatal error. Parameters
| Name | Type | Description |
|---|---|---|
warn | string | The warning |
| Source |