Class: VoiceConnection

VoiceConnection

Represents a connection to a guild's voice server. ```js // Obtained using: voiceChannel.join() .then(connection => { }); ```

Constructor

new VoiceConnection()

Implements:
Source:

Extends

  • EventEmitter

Members

(private) _speaking :Map.<Snowflake, Readonly.<Speaking>>

Tracks which users are talking
Type:
Source:

(private) authentication :Object

The authentication data needed to connect to the voice server
Type:
  • Object
Source:

channel :VoiceChannel

The voice channel this connection is currently serving
Type:
Source:

(readonly) client :Client

The client that instantiated this connection
Type:
Source:

(readonly, nullable) dispatcher :StreamDispatcher

The current stream dispatcher (if any)
Type:
Source:

player :AudioPlayer

The audio player for this voice connection
Type:
Source:

receiver :VoiceReceiver

The voice receiver of this connection
Type:
Source:

(private) sockets :Object

Object that wraps contains the `ws` and `udp` sockets of this voice connection
Type:
  • Object
Source:

speaking :Readonly.<Speaking>

Our current speaking state
Type:
Source:

(private) ssrcMap :Map.<number, Snowflake>

Map SSRC values to user IDs
Type:
Source:

status :VoiceStatus

The current status of the voice connection
Type:
Source:

voice :VoiceState

The voice state of this connection
Type:
Source:

voiceManager :ClientVoiceManager

The voice manager that instantiated this connection
Type:
Source:

Methods

(private) _disconnect()

Internally disconnects (doesn't send disconnect packet).
Source:

(private) authenticate()

Attempts to authenticate to the voice server.
Source:

(private) authenticateFailed(reason)

Invoked when we fail to initiate a voice connection.
Parameters:
Name Type Description
reason string The reason for failure
Source:

(private) checkAuthenticated()

Checks whether the voice connection is authenticated.
Source:

(private) cleanup()

Cleans up after disconnect.
Source:

(private) connect()

Connect the voice connection.
Source:

disconnect()

Disconnects the voice connection, causing a disconnect and closing event to be emitted.
Source:

(private) onReady(data)

Invoked when the voice websocket is ready.
Parameters:
Name Type Description
data Object The received data
Source:

(private) onSessionDescription(data)

Invoked when a session description is received.
Parameters:
Name Type Description
data Object The received data
Source:

(private) onSpeaking(data)

Invoked when a speaking event is received.
Parameters:
Name Type Description
data Object The received data
Source:

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
Source:

(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
Source:
Returns:
Type
Promise.<Shard>

(private) setSessionID(sessionID)

Sets the Session ID for the connection.
Parameters:
Name Type Description
sessionID string The voice session ID
Source:

setSpeaking(value)

Sets whether the voice connection should display as "speaking", "soundshare" or "none".
Parameters:
Name Type Description
value BitFieldResolvable The new speaking state
Source:

(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
Source:
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
Source:

Events

authenticated

Emitted when we successfully initiate a voice connection.
Source:

debug

Debug info from the connection.
Parameters:
Name Type Description
message string The debug message
Source:

disconnect

Emitted when the voice connection disconnects.
Source:

error

Emitted whenever the connection encounters an error.
Parameters:
Name Type Description
error Error The encountered error
Source:

failed

Emitted when we fail to initiate a voice connection.
Parameters:
Name Type Description
error Error The encountered error
Source:

newSession

Emitted when a new session ID is received.
Source:

ready

Emitted once the connection is ready, when a promise to join a voice channel resolves, the connection will already be ready.
Source:

reconnecting

Emitted when the voice connection is reconnecting (typically after a region change).
Source:

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
Source:

warn

Warning info from the connection.
Parameters:
Name Type Description
warning string | Error The warning
Source: