Extends
- EventEmitter
Members
(private) _speaking :Map.<Snowflake, Readonly.<Speaking>>
Tracks which users are talking
Type:
(private) authentication :Object
The authentication data needed to connect to the voice server
Type:
- Object
channel :VoiceChannel
The voice channel this connection is currently serving
Type:
(readonly) client :Client
The client that instantiated this connection
Type:
(readonly, nullable) dispatcher :StreamDispatcher
The current stream dispatcher (if any)
Type:
player :AudioPlayer
The audio player for this voice connection
Type:
receiver :VoiceReceiver
The voice receiver of this connection
Type:
(private) sockets :Object
Object that wraps contains the `ws` and `udp` sockets of this voice connection
Type:
- Object
speaking :Readonly.<Speaking>
Our current speaking state
Type:
- Readonly.<Speaking>
(private) ssrcMap :Map.<number, Snowflake>
Map SSRC values to user IDs
Type:
- Map.<number, Snowflake>
status :VoiceStatus
The current status of the voice connection
Type:
voice :VoiceState
The voice state of this connection
Type:
voiceManager :ClientVoiceManager
The voice manager that instantiated this connection
Type:
Methods
(private) _disconnect()
Internally disconnects (doesn't send disconnect packet).
(private) authenticate()
Attempts to authenticate to the voice server.
(private) authenticateFailed(reason)
Invoked when we fail to initiate a voice connection.
Parameters:
Name | Type | Description |
---|---|---|
reason |
string | The reason for failure |
(private) checkAuthenticated()
Checks whether the voice connection is authenticated.
(private) cleanup()
Cleans up after disconnect.
(private) connect()
Connect the voice connection.
disconnect()
Disconnects the voice connection, causing a disconnect and closing event to be emitted.
(private) onReady(data)
Invoked when the voice websocket is ready.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The received data |
(private) onSessionDescription(data)
Invoked when a session description is received.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The received data |
(private) onSpeaking(data)
Invoked when a speaking event is received.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The received data |
play(resource, optionsopt) → {StreamDispatcher}
Play an audio resource.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
resource |
VoiceBroadcast | ReadableStream | string | The resource to play. | |
options |
StreamOptions |
<optional> |
The options to play. |
- Implements:
- Source:
Returns:
- Type
- StreamDispatcher
Examples
// Play a local audio file
connection.play('/home/hydrabolt/audio.mp3', { volume: 0.5 });
// Play a ReadableStream
connection.play(ytdl('https://www.youtube.com/watch?v=ZlAU_w7-Xp8', { quality: 'highestaudio' }));
// Play a voice broadcast
const broadcast = client.voice.createBroadcast();
broadcast.play('/home/hydrabolt/audio.mp3');
connection.play(broadcast);
// Using different protocols: https://ffmpeg.org/ffmpeg-protocols.html
connection.play('http://www.sample-videos.com/audio/mp3/wave.mp3');
(private) reconnect(token, endpoint)
Attempts to reconnect to the voice server (typically after a region change).
Parameters:
Name | Type | Description |
---|---|---|
token |
string | The voice token |
endpoint |
string | The voice endpoint |
(private) sendVoiceStateUpdate(optionsopt) → {Promise.<Shard>}
Sends a request to the main gateway to join a voice channel.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object |
<optional> |
The options to provide |
Returns:
- Type
- Promise.<Shard>
(private) setSessionID(sessionID)
Sets the Session ID for the connection.
Parameters:
Name | Type | Description |
---|---|---|
sessionID |
string | The voice session ID |
setSpeaking(value)
Sets whether the voice connection should display as "speaking", "soundshare" or "none".
Parameters:
Name | Type | Description |
---|---|---|
value |
BitFieldResolvable | The new speaking state |
(private) setTokenAndEndpoint(token, endpoint) → {void}
Set the token and endpoint required to connect to the voice servers.
Parameters:
Name | Type | Description |
---|---|---|
token |
string | The voice token |
endpoint |
string | The voice endpoint |
Returns:
- Type
- void
(private) updateChannel(channel)
Move to a different voice channel in the same guild.
Parameters:
Name | Type | Description |
---|---|---|
channel |
VoiceChannel | The channel to move to |
Events
authenticated
Emitted when we successfully initiate a voice connection.
debug
Debug info from the connection.
Parameters:
Name | Type | Description |
---|---|---|
message |
string | The debug message |
disconnect
Emitted when the voice connection disconnects.
error
Emitted whenever the connection encounters an error.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | The encountered error |
failed
Emitted when we fail to initiate a voice connection.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | The encountered error |
newSession
Emitted when a new session ID is received.
ready
Emitted once the connection is ready, when a promise to join a voice channel resolves,
the connection will already be ready.
reconnecting
Emitted when the voice connection is reconnecting (typically after a region change).
speaking
Emitted whenever a user changes speaking state.
Parameters:
Name | Type | Description |
---|---|---|
user |
User | The user that has changed speaking state |
speaking |
Readonly.<Speaking> | The speaking state of the user |
warn
Warning info from the connection.
Parameters:
Name | Type | Description |
---|---|---|
warning |
string | Error | The warning |