Appearance
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
| Name | Type | Optional | Description |
|---|---|---|---|
client | Client | No | The erin.js client instance |
channel | VoiceChannel | No | The voice channel to connect to |
_userId | string | No | The user ID (reserved for future use) |
Properties
| Name | Type | Readonly | Optional | Description |
|---|---|---|---|---|
activeSpeakers | Set<string> | Yes | No | |
audioSource | AudioSource | null | No | No | |
audioTrack | LocalAudioTrack | null | No | No | |
channel | VoiceChannel | Yes | No | |
client | Client | Yes | No | |
currentStream | { destroy?: () => void; } | null | No | No | |
currentVideoStream | { destroy?: () => void; } | null | No | No | |
guildId | string | Yes | No | |
lastServerEndpoint | string | null | No | No | |
lastServerToken | string | null | No | No | |
participantTrackSids | Map<string, string> | Yes | No | |
playing | boolean | Yes | No | Whether audio is currently playing. |
playingVideo | boolean | Yes | No | Whether a video track is currently playing in the voice channel. |
receiveSubscriptions | Map<string, LiveKitReceiveSubscription> | Yes | No | |
requestedSubscriptions | Map<string, boolean> | Yes | No | |
room | Room | null | No | No | |
videoSource | VideoSource | null | No | No | |
videoTrack | LocalVideoTrack | null | No | No |
Methods
audioDebug()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
msg | string | No | |
data | object | Yes |
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:
| Name | Type | Optional | Description |
|---|---|---|---|
server | GatewayVoiceServerUpdateDispatchData | No | Voice server update data (endpoint, token) |
_state | GatewayVoiceStateUpdateDispatchData | No | Voice state update data (session, channel) |
debug()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
msg | string | No | |
data | string | object | Yes |
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:
| Name | Type | Optional | Description |
|---|---|---|---|
source | string | No |
getParticipantId()
Returns: string
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
participant | RemoteParticipant | No |
getVolume()
Get current volume (0-200).
Returns: number
Parameters:
None
isAudioTrack()
Returns: boolean
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
track | RemoteTrack | No |
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:
| Name | Type | Optional | Description |
|---|---|---|---|
endpoint | string | null | No | Voice server endpoint from the gateway |
token | string | No | Voice 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:
| Name | Type | Optional | Description |
|---|---|---|---|
urlOrStream | string | NodeJS.ReadableStream | No | Audio source: HTTP(S) URL to a WebM/Opus file, or a Node.js ReadableStream |
playOpus()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
_stream | NodeJS.ReadableStream | No |
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:
| Name | Type | Optional | Description |
|---|---|---|---|
urlOrBuffer | string | ArrayBuffer | Uint8Array<ArrayBufferLike> | No | Video source: HTTP(S) URL to an MP4 file, or raw ArrayBuffer/Uint8Array of MP4 data |
options | VideoPlayOptions | Yes | Optional 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:
| Name | Type | Optional | Description |
|---|---|---|---|
url | string | No | |
options | VideoPlayOptions | Yes |
setVolume()
Set playback volume (0-200, 100 = normal). Affects current and future playback.
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
volumePercent | number | No |
stop()
Stop playback and clear both audio and video tracks.
Returns: void
Parameters:
None
stopVideo()
Returns: void
Parameters:
None
subscribeParticipantAudio()
Returns: LiveKitReceiveSubscription
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
participantId | string | No | |
options | { autoResubscribe?: boolean; } | No |
subscribeParticipantTrack()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
participant | RemoteParticipant | No | |
track | RemoteTrack | No | |
options | { autoSubscribe?: boolean; } | No |