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