Skip to content

VoiceManager

Package: @erinjs/voice

Manages voice connections. Use getVoiceManager(client) to obtain an instance.

Constructor

NameTypeOptionalDescription
clientClientNo
optionsVoiceManagerOptionsNo

Properties

NameTypeReadonlyOptionalDescription
clientClientYesNo
connectionIdsMap<string, string>YesNochannel_id -> connection_id (from VoiceServerUpdate; required for voice state updates)
connectionsanyYesNochannel_id -> connection (erin.js multi-channel: allows multiple connections per guild)
pendingMap<string, { channel: VoiceChannel; resolve: (c: VoiceConnection | LiveKitRtcConnection) => void; reject: (e: Error) => void; server?: any; state?: any; }>YesNochannel_id -> pending join
shardIdnumberYesNo
voiceStatesVoiceStateMapYesNoguild_id -> user_id -> channel_id

Methods

getConnection()

Get the active voice connection for a channel or guild.

Returns: VoiceConnection | LiveKitRtcConnection | undefined

Parameters:

NameTypeOptionalDescription
channelOrGuildIdstringNoChannel ID (primary) or guild ID (returns first connection in that guild)

getVoiceChannelId()

Get the voice channel ID the user is currently in, or null if not in voice.

Returns: string | null

Parameters:

NameTypeOptionalDescription
guildIdstringNoGuild ID to look up
userIdstringNoUser ID to look up

handleVoiceServerUpdate()

Returns: void

Parameters:

NameTypeOptionalDescription
dataGatewayVoiceServerUpdateDispatchDataNo

handleVoiceStatesSync()

Returns: void

Parameters:

NameTypeOptionalDescription
data{ guildId: string; voiceStates: Array<{ user_id: string; channel_id: string | null; }>; }No

handleVoiceStateUpdate()

Returns: void

Parameters:

NameTypeOptionalDescription
dataGatewayVoiceStateUpdateDispatchDataNo

join() async

Join a voice channel. Resolves when the connection is ready. Supports multiple connections per guild (erin.js multi-channel).

Returns: Promise<VoiceConnection | LiveKitRtcConnection>

Parameters:

NameTypeOptionalDescription
channelVoiceChannelNoThe voice channel to join

leave()

Leave all voice channels in a guild. With multi-channel support, disconnects from every channel in the guild.

Returns: void

Parameters:

NameTypeOptionalDescription
guildIdstringNoGuild ID to leave

leaveChannel()

Leave a specific voice channel by channel ID.

Returns: void

Parameters:

NameTypeOptionalDescription
channelIdstringNoChannel ID to leave

listParticipantsInChannel()

List participant user IDs currently in a specific voice channel.

Returns: string[]

Parameters:

NameTypeOptionalDescription
guildIdstringNo
channelIdstringNo

registerConnection()

Returns: void

Parameters:

NameTypeOptionalDescription
channelIdstringNo
connVoiceConnection | LiveKitRtcConnectionNo

storeConnectionId()

Returns: void

Parameters:

NameTypeOptionalDescription
channelIdstringNo
connectionIdstring | null | undefinedNo

subscribeChannelParticipants()

Subscribe to inbound audio for all known participants currently in a voice channel. Only supported for LiveKit connections.

Returns: LiveKitReceiveSubscription[]

Parameters:

NameTypeOptionalDescription
channelIdstringNo
opts{ autoResubscribe?: boolean; }Yes

tryCompletePending()

Returns: void

Parameters:

NameTypeOptionalDescription
channelIdstringNo
pending{ channel: VoiceChannel; resolve: (c: VoiceConnection | LiveKitRtcConnection) => void; reject: (e: Error) => void; server?: GatewayVoiceServerUpdateDispatchData; state?: GatewayVoiceStateUpdateDispatchData; }No

updateVoiceState()

Update voice state (e.g. self_stream, self_video) while in a channel. Sends a VoiceStateUpdate to the gateway so the server and clients see the change. Requires connection_id (from VoiceServerUpdate); without it, the gateway would treat the update as a new join and trigger a new VoiceServerUpdate, causing connection loops.

Returns: void

Parameters:

NameTypeOptionalDescription
channelIdstringNoChannel ID (connection key)
partial{ self_stream?: boolean; self_video?: boolean; self_mute?: boolean; self_deaf?: boolean; }NoPartial voice state to update (self_stream, self_video, self_mute, self_deaf)

uploadStreamPreview() async

Upload a placeholder stream preview so the preview URL returns 200 instead of 404.

Returns: Promise<void>

Parameters:

NameTypeOptionalDescription
channelIdstringNo
connVoiceConnection | LiveKitRtcConnectionNo

Released under the Apache-2.0 License.