Skip to content

StreamConnection ​

classe · Source

Represents a connection to a guild's voice server.

js
// Obtained using:
client.voice.joinChannel(channel)
  .then(connection => connection.createStreamConnection())
   .then(connection => {

  });

Extends: VoiceConnection

Constructor ​

new StreamConnection(voiceManager: ClientVoiceManager, channel: Channel, voiceConnection: VoiceConnection)

Parameters

NameTypeDescription
voiceManagerClientVoiceManagerVoice manager
channelChannelany channel (joinable)
voiceConnectionVoiceConnectionparent

Properties ​

voiceConnection ​

voiceConnection: VoiceConnection

Current voice connection Source

serverId ​

serverId: string | null

Server Id Source

isPaused ​

isPaused: boolean | null

Stream state Source

viewerIds ​

viewerIds: Array<Snowflake>

Viewer IDs Source

region ​

region: string | null

Voice region name Source

streamKey ​

streamKey: string

Current stream key Source

voiceManager ​

voiceManager: ClientVoiceManager

The voice manager that instantiated this connection Source

channel ​

channel: VoiceChannel

The voice channel this connection is currently serving Source

status ​

status: VoiceStatus

The current status of the voice connection Source

speaking ​

speaking: Readonly<Speaking>

Our current speaking state Source

videoStatus ​

videoStatus: boolean | null

Our current video state Source

authentication ​

private

authentication: Object

The authentication data needed to connect to the voice server Source

player ​

player: MediaPlayer

The audio player for this voice connection Source

ssrcMap ​

private

ssrcMap: Map<number, {userId: Snowflake, speaking: boolean, hasVideo: boolean}>

Map SSRC values to user IDs Source

_speaking ​

private

_speaking: Map<Snowflake, Readonly<Speaking>>

Tracks which users are talking Source

sockets ​

private

sockets: Object

Object that wraps contains the ws and udp sockets of this voice connection Source

receiver ​

receiver: VoiceReceiver

The voice receiver of this connection Source

videoCodec ​

videoCodec: VideoCodec

Video codec (encoded) of this connection Source

streamConnection ​

nullable

streamConnection: StreamConnection

Create a stream connection ? Source

streamWatchConnection ​

streamWatchConnection: Collection<Snowflake, StreamConnectionReadonly>

All stream watch connection Source

client ​

readonly

client: Client

The client that instantiated this connection Source

dispatcher ​

readonly · nullable

dispatcher: AudioDispatcher

The current audio dispatcher (if any) Source

videoDispatcher ​

readonly · nullable

videoDispatcher: VideoDispatcher

The current video dispatcher (if any) Source

voice ​

nullable

voice: VoiceState

The voice state of this connection Source

Methods ​

sendSignalScreenshare ​

sendSignalScreenshare(): void

Create new stream connection (WS packet) Returns: voidSource

sendScreenshareState ​

sendScreenshareState(isPaused: boolean): void

Send screenshare state... (WS) Parameters

NameTypeDescription
isPausedbooleanscreenshare paused ? Default: false.

Returns: voidSource

sendStopScreenshare ​

private

sendStopScreenshare(): void

Stop screenshare, delete this connection (WS) Returns: voidSource

setSpeaking ​

setSpeaking(value: BitFieldResolvable)

Set the speaking state Parameters

NameTypeDescription
valueBitFieldResolvableThe new speaking state
Source

setVideoCodec ​

setVideoCodec(value: VideoCodec): VoiceConnection

Set video codec before select protocol Parameters

NameTypeDescription
valueVideoCodecCodec

Returns: VoiceConnectionSource

setVideoStatus ​

setVideoStatus(value: boolean)

Sets video status Parameters

NameTypeDescription
valuebooleanVideo on or off
Source

sendVoiceStateUpdate ​

private

sendVoiceStateUpdate(options?: Object): Promise<Shard>

Sends a request to the main gateway to join a voice channel. Parameters

NameTypeDescription
options?ObjectThe options to provide

Returns: Promise<Shard>Source

setTokenAndEndpoint ​

private

setTokenAndEndpoint(token: string, endpoint: string): void

Set the token and endpoint required to connect to the voice servers. Parameters

NameTypeDescription
tokenstringThe voice token
endpointstringThe voice endpoint

Returns: voidSource

setSessionId ​

private

setSessionId(sessionId: string)

Sets the Session ID for the connection. Parameters

NameTypeDescription
sessionIdstringThe voice session ID
Source

checkAuthenticated ​

private

checkAuthenticated()

Checks whether the voice connection is authenticated. Source

authenticateFailed ​

private

authenticateFailed(reason: string)

Invoked when we fail to initiate a voice connection. Parameters

NameTypeDescription
reasonstringThe reason for failure
Source

updateChannel ​

private

updateChannel(channel: VoiceChannel)

Move to a different voice channel in the same guild. Parameters

NameTypeDescription
channelVoiceChannelThe channel to move to
Source

authenticate ​

private

authenticate(options: Object)

Attempts to authenticate to the voice server. Parameters

NameTypeDescription
optionsObjectJoin config
Source

reconnect ​

private

reconnect(token: string, endpoint: string)

Attempts to reconnect to the voice server (typically after a region change). Parameters

NameTypeDescription
tokenstringThe voice token
endpointstringThe voice endpoint
Source

disconnect ​

disconnect()

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

_disconnect ​

private

_disconnect()

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

cleanup ​

private

cleanup()

Cleans up after disconnect. Source

connect ​

private

connect()

Connect the voice connection. Source

onReady ​

private

onReady(data: Object)

Invoked when the voice websocket is ready. Parameters

NameTypeDescription
dataObjectThe received data
Source

onSessionDescription ​

private

onSessionDescription(data: Object)

Invoked when a session description is received. Parameters

NameTypeDescription
dataObjectThe received data
Source

onSpeaking ​

private

onSpeaking(data: Object)

Invoked when a speaking event is received. Parameters

NameTypeDescription
dataObjectThe received data
Source

createStreamConnection ​

createStreamConnection(): Promise<StreamConnection>

Create new connection to screenshare stream Returns: Promise<StreamConnection>Source

joinStreamConnection ​

async

async joinStreamConnection(user: UserResolvable): Promise<StreamConnectionReadonly>

Watch user stream Parameters

NameTypeDescription
userUserResolvableDiscord user

Returns: Promise<StreamConnectionReadonly>Source

playAudio ​

playAudio(resource: ReadableStream | string, options?: StreamOptions): AudioDispatcher

Play an audio resource. Parameters

NameTypeDescription
resourceReadableStream | stringThe resource to play.
options?StreamOptionsThe options to play.

Returns: AudioDispatcher

js
// Play a local audio file
connection.playAudio('/home/hydrabolt/audio.mp3', { volume: 0.5 });
js
// Play a ReadableStream
connection.playAudio(ytdl('https://www.youtube.com/watch?v=ZlAU_w7-Xp8', { quality: 'highestaudio' }));
js
// Using different protocols: https://ffmpeg.org/ffmpeg-protocols.html
connection.playAudio('http://www.sample-videos.com/audio/mp3/wave.mp3');

Source

playVideo ​

playVideo(resource: ReadableStream | string, options?: VideoOptions): VideoDispatcher

Play a video resource. Parameters

NameTypeDescription
resourceReadableStream | stringThe resource to play.
options?VideoOptionsThe options to play.

Returns: VideoDispatcher

js
// Play a local video file
connection.playVideo('/home/hydrabolt/video.mp4');
js
// Using different protocols: https://ffmpeg.org/ffmpeg-protocols.html
connection.playVideo('http://www.sample-videos.com/video/mp4/wave.mp4');

Source

Events ​

debug ​

debug: unknown

Debug info from the connection. Parameters

NameTypeDescription
messagestringThe debug message
Source

warn ​

warn: unknown

Warning info from the connection. Parameters

NameTypeDescription
warningstring | ErrorThe warning
Source

newSession ​

newSession: unknown

Emitted when a new session ID is received. Source

authenticated ​

authenticated: unknown

Emitted when we successfully initiate a voice connection. Source

failed ​

failed: unknown

Emitted when we fail to initiate a voice connection. Parameters

NameTypeDescription
errorErrorThe encountered error
Source

error ​

error: unknown

Emitted whenever the connection encounters an error. Parameters

NameTypeDescription
errorErrorThe encountered error
Source

reconnecting ​

reconnecting: unknown

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

disconnect ​

disconnect: unknown

Emitted when the voice connection disconnects. Source

ready ​

ready: unknown

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

speaking ​

speaking: unknown

Emitted whenever a user changes speaking state. Parameters

NameTypeDescription
userUserThe user that has changed speaking state
speakingReadonly<Speaking>The speaking state of the user
Source

Unofficial software. Not affiliated with or supported by Discord.