Skip to content

LiveKitRtcConnection

Package: @erinjs/voice

Voice connection using LiveKit RTC. Used when erin.js routes voice to LiveKit.

Supports both audio playback ({@link play}) and video streaming ({@link playVideo}) to voice channels. Video uses node-webcodecs for decoding (no ffmpeg subprocess). Audio uses prism-media WebM demuxer.

Constructor

NameTypeOptionalDescription
clientClientNoThe erin.js client instance
channelVoiceChannelNoThe voice channel to connect to
_userIdstringNoThe user ID (reserved for future use)

Properties

NameTypeReadonlyOptionalDescription
activeSpeakersSet<string>YesNo
audioSourceAudioSource | nullNoNo
audioTrackLocalAudioTrack | nullNoNo
channelVoiceChannelYesNo
clientClientYesNo
currentStream{ destroy?: () => void; } | nullNoNo
currentVideoStream{ destroy?: () => void; } | nullNoNo
guildIdstringYesNo
lastServerEndpointstring | nullNoNo
lastServerTokenstring | nullNoNo
participantTrackSidsMap<string, string>YesNo
playingbooleanYesNoWhether audio is currently playing.
playingVideobooleanYesNoWhether a video track is currently playing in the voice channel.
receiveSubscriptionsMap<string, LiveKitReceiveSubscription>YesNo
requestedSubscriptionsMap<string, boolean>YesNo
roomRoom | nullNoNo
videoSourceVideoSource | nullNoNo
videoTrackLocalVideoTrack | nullNoNo

Methods

audioDebug()

Returns: void

Parameters:

NameTypeOptionalDescription
msgstringNo
dataobjectYes

clearReceiveSubscriptions()

Returns: void

Parameters:

None


connect() async

Connect to the LiveKit room using voice server and state from the gateway. Called internally by VoiceManager; typically not used directly.

Returns: Promise<void>

Parameters:

NameTypeOptionalDescription
serverGatewayVoiceServerUpdateDispatchDataNoVoice server update data (endpoint, token)
_stateGatewayVoiceStateUpdateDispatchDataNoVoice state update data (session, channel)

debug()

Returns: void

Parameters:

NameTypeOptionalDescription
msgstringNo
datastring | objectYes

destroy()

Disconnect from the room and remove all event listeners.

Returns: void

Parameters:

None


disconnect()

Disconnect from the LiveKit room and stop all playback.

Returns: void

Parameters:

None


emitDisconnect()

Returns: void

Parameters:

NameTypeOptionalDescription
sourcestringNo

getParticipantId()

Returns: string

Parameters:

NameTypeOptionalDescription
participantRemoteParticipantNo

getVolume()

Get current volume (0-200).

Returns: number

Parameters:

None


isAudioTrack()

Returns: boolean

Parameters:

NameTypeOptionalDescription
trackRemoteTrackNo

isConnected()

Returns true if the LiveKit room is connected and not destroyed.

Returns: boolean

Parameters:

None


isSameServer()

Returns true if we're already connected to the given server (skip migration).

Returns: boolean

Parameters:

NameTypeOptionalDescription
endpointstring | nullNoVoice server endpoint from the gateway
tokenstringNoVoice server token

play() async

Play audio from a WebM/Opus URL or readable stream. Publishes to the LiveKit room as an audio track.

Returns: Promise<void>

Parameters:

NameTypeOptionalDescription
urlOrStreamstring | NodeJS.ReadableStreamNoAudio source: HTTP(S) URL to a WebM/Opus file, or a Node.js ReadableStream

playOpus()

Returns: void

Parameters:

NameTypeOptionalDescription
_streamNodeJS.ReadableStreamNo

playVideo() async

Play video from an MP4 URL or buffer. Streams decoded frames to the LiveKit room as a video track. Uses node-webcodecs for decoding (no ffmpeg). Supports H.264 (avc1) and H.265 (hvc1/hev1) codecs.

Returns: Promise<void>

Parameters:

NameTypeOptionalDescription
urlOrBufferstring | ArrayBuffer | Uint8Array<ArrayBufferLike>NoVideo source: HTTP(S) URL to an MP4 file, or raw ArrayBuffer/Uint8Array of MP4 data
optionsVideoPlayOptionsYesOptional playback options (see {@link VideoPlayOptions})

playVideoFFmpeg() async

FFmpeg-based video playback. Bypasses node-webcodecs to avoid libc++abi crashes on macOS. Requires ffmpeg and ffprobe in PATH. URL input only.

Returns: Promise<void>

Parameters:

NameTypeOptionalDescription
urlstringNo
optionsVideoPlayOptionsYes

setVolume()

Set playback volume (0-200, 100 = normal). Affects current and future playback.

Returns: void

Parameters:

NameTypeOptionalDescription
volumePercentnumberNo

stop()

Stop playback and clear both audio and video tracks.

Returns: void

Parameters:

None


stopVideo()

Returns: void

Parameters:

None


subscribeParticipantAudio()

Returns: LiveKitReceiveSubscription

Parameters:

NameTypeOptionalDescription
participantIdstringNo
options{ autoResubscribe?: boolean; }No

subscribeParticipantTrack()

Returns: void

Parameters:

NameTypeOptionalDescription
participantRemoteParticipantNo
trackRemoteTrackNo
options{ autoSubscribe?: boolean; }No

Released under the Apache-2.0 License.