StreamConnectionReadonly
classe · Source
Represents a connection to a guild's voice server.
// Obtained using:
client.voice.joinChannel(channel)
.then(connection => connection.createStreamConnection())
.then(connection => {
});Extends: VoiceConnection
Constructor
Parameters
| Name | Type | Description |
|---|---|---|
voiceManager | ClientVoiceManager | Voice manager |
channel | Channel | any channel (joinable) |
voiceConnection | VoiceConnection | parent |
userId | Snowflake | User ID |
Properties
voiceConnection
Current voice connection Source
userId
User ID (who started the stream) Source
serverId
Server Id Source
isPaused
Stream state Source
viewerIds
Viewer IDs Source
region
Voice region name Source
streamKey
Current stream key Source
voiceManager
The voice manager that instantiated this connection Source
channel
The voice channel this connection is currently serving Source
status
The current status of the voice connection Source
speaking
Our current speaking state Source
videoStatus
Our current video state Source
authentication
The authentication data needed to connect to the voice server Source
player
The audio player for this voice connection Source
ssrcMap
Map SSRC values to user IDs Source
_speaking
Tracks which users are talking Source
sockets
Object that wraps contains the ws and udp sockets of this voice connection Source
receiver
The voice receiver of this connection Source
videoCodec
Video codec (encoded) of this connection Source
streamConnection
Create a stream connection ? Source
streamWatchConnection
All stream watch connection Source
client
The client that instantiated this connection Source
dispatcher
The current audio dispatcher (if any) Source
videoDispatcher
The current video dispatcher (if any) Source
voice
The voice state of this connection Source
Methods
sendSignalScreenshare
Create new stream connection (WS packet) Returns: voidSource
sendStopScreenshare
Stop screenshare, delete this connection (WS) Returns: voidSource
setSpeaking
Sets whether the voice connection should display as "speaking", "soundshare" or "none". Parameters
| Name | Type | Description |
|---|---|---|
value | BitFieldResolvable | The new speaking state |
| Source |
setVideoCodec
Set video codec before select protocol Parameters
| Name | Type | Description |
|---|---|---|
value | VideoCodec | Codec |
Returns: VoiceConnectionSource
setVideoStatus
Sets video status Parameters
| Name | Type | Description |
|---|---|---|
value | boolean | Video on or off |
| Source |
sendVoiceStateUpdate
Sends a request to the main gateway to join a voice channel. Parameters
| Name | Type | Description |
|---|---|---|
options? | Object | The options to provide |
Returns: Promise<Shard>Source
setTokenAndEndpoint
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: voidSource
setSessionId
Sets the Session ID for the connection. Parameters
| Name | Type | Description |
|---|---|---|
sessionId | string | The voice session ID |
| Source |
checkAuthenticated
Checks whether the voice connection is authenticated. Source
authenticateFailed
Invoked when we fail to initiate a voice connection. Parameters
| Name | Type | Description |
|---|---|---|
reason | string | The reason for failure |
| Source |
updateChannel
Move to a different voice channel in the same guild. Parameters
| Name | Type | Description |
|---|---|---|
channel | VoiceChannel | The channel to move to |
| Source |
authenticate
Attempts to authenticate to the voice server. Parameters
| Name | Type | Description |
|---|---|---|
options | Object | Join config |
| Source |
reconnect
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 |
disconnect
Disconnects the voice connection, causing a disconnect and closing event to be emitted. Source
_disconnect
Internally disconnects (doesn't send disconnect packet). Source
cleanup
Cleans up after disconnect. Source
connect
Connect the voice connection. Source
onReady
Invoked when the voice websocket is ready. Parameters
| Name | Type | Description |
|---|---|---|
data | Object | The received data |
| Source |
onSessionDescription
Invoked when a session description is received. Parameters
| Name | Type | Description |
|---|---|---|
data | Object | The received data |
| Source |
onSpeaking
Invoked when a speaking event is received. Parameters
| Name | Type | Description |
|---|---|---|
data | Object | The received data |
| Source |
createStreamConnection
Create new connection to screenshare stream Returns: Promise<StreamConnection>Source
joinStreamConnection
Watch user stream Parameters
| Name | Type | Description |
|---|---|---|
user | UserResolvable | Discord user |
Returns: Promise<StreamConnectionReadonly>Source
playAudio
Play an audio resource. Parameters
| Name | Type | Description |
|---|---|---|
resource | ReadableStream | string | The resource to play. |
options? | StreamOptions | The options to play. |
Returns: AudioDispatcher
// Play a local audio file
connection.playAudio('/home/hydrabolt/audio.mp3', { volume: 0.5 });// Play a ReadableStream
connection.playAudio(ytdl('https://www.youtube.com/watch?v=ZlAU_w7-Xp8', { quality: 'highestaudio' }));// Using different protocols: https://ffmpeg.org/ffmpeg-protocols.html
connection.playAudio('http://www.sample-videos.com/audio/mp3/wave.mp3');playVideo
Play a video resource. Parameters
| Name | Type | Description |
|---|---|---|
resource | ReadableStream | string | The resource to play. |
options? | VideoOptions | The options to play. |
Returns: VideoDispatcher
// Play a local video file
connection.playVideo('/home/hydrabolt/video.mp4');// Using different protocols: https://ffmpeg.org/ffmpeg-protocols.html
connection.playVideo('http://www.sample-videos.com/video/mp4/wave.mp4');Events
debug
Debug info from the connection. Parameters
| Name | Type | Description |
|---|---|---|
message | string | The debug message |
| Source |
warn
Warning info from the connection. Parameters
| Name | Type | Description |
|---|---|---|
warning | string | Error | The warning |
| Source |
newSession
Emitted when a new session ID is received. Source
authenticated
Emitted when we successfully initiate a voice connection. Source
failed
Emitted when we fail to initiate a voice connection. Parameters
| Name | Type | Description |
|---|---|---|
error | Error | The encountered error |
| Source |
error
Emitted whenever the connection encounters an error. Parameters
| Name | Type | Description |
|---|---|---|
error | Error | The encountered error |
| Source |
reconnecting
Emitted when the voice connection is reconnecting (typically after a region change). Source
disconnect
Emitted when the voice connection disconnects. Source
ready
Emitted once the connection is ready, when a promise to join a voice channel resolves, the connection will already be ready. 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 |