livekitWebRTC Service
File: src/services/livekitWebRTC.ts
Overview
Exports
- UserMediaState - interface export
- LiveKitConfig - interface export
- LiveKitWebRTCService - class export
- livekitWebRTC - const export
Functions
resolveIdentityToUuid(identity: string, remoteServerDomain?: string | null)
No description available.
Parameters:
identity: stringremoteServerDomain?: string | null
Returns: Promise<string | null>
typescript
/**
* LiveKit WebRTC Service
*
* Provides a SFU-based WebRTC implementation using LiveKit.
* Mirrors the unifiedWebRTC API for seamless switching between SFU and P2P modes.
*
* Features:
* - Selective Forwarding Unit (SFU) for efficient media routing
* - Built-in E2EE support
* - Scales to large rooms (stage events)
* - Automatic quality adaptation
*/
import {
Room,
RoomEvent,
RemoteParticipant,
LocalParticipant,
Track,
TrackPublication,
ConnectionState,
ParticipantEvent,
LocalTrack,
LocalAudioTrack,
LocalVideoTrack,
RemoteTrack,
RemoteAudioTrack,
RemoteVideoTrack,
VideoPresets,
AudioPresets,
createLocalAudioTrack,
createLocalVideoTrack,
setLogLevel,
LogLevel,
ExternalE2EEKeyProvider,
} from 'livekit-client';
import { supabase } from '@/supabase';
import { debug } from '@/utils/debug';
import { userStorage } from '@/utils/userScopedStorage';
import { VoiceSettingsService } from './VoiceSettingsService';
// =============================================================================
// FEDERATED IDENTITY HELPERS
// =============================================================================
// Cache for federated ID to profile UUID mappings
const federatedIdToUuidCache = new Map<string, string>();
// Reverse cache: UUID to LiveKit identity (for looking up participants by UUID)
const uuidToIdentityCache = new Map<string, string>();
/**
* Resolve a LiveKit identity to a profile UUID
* For local users, identity is already the UUID
* For federated users, identity is `federated:{federatedId}` and we need to look up the UUID
* @param identity - The LiveKit participant identity
* @param remoteServerDomain - Optional domain of the remote server (for resolving non-federated identities from remote servers)
*/
async function resolveIdentityToUuid(identity: string, remoteServerDomain?: string | null): Promise<string | null>resolveFederatedId(federatedId: string, originalIdentity: string)
No description available.
Parameters:
federatedId: stringoriginalIdentity: string
Returns: Promise<string | null>
typescript
/**
* Resolve a federated ID (actor URL) to a local profile UUID
*/
async function resolveFederatedId(federatedId: string, originalIdentity: string): Promise<string | null>Classes
LiveKitWebRTCService
No description available.
Methods:
constructorgetResolutionPresetswitchgetConfigcatchisAvailablegetTokengetFederatedTokenjoinChanneljoinWithTokenleaveChannelpublishLocalAudiotoggleVideotoggleScreenSharetoggleMutesetMutedtoggleDeafenupdateStreamQualityloadStreamQualitySettingssetUserMicVolumesetUserScreenShareVolumegetUserMicVolumegetUserScreenShareVolumefindAudioElementByResolvedIdhasScreenShareAudiogetLocalStreamgetUserStreamattachVideoToElementdetachVideoFromElementgetLocalStategetAllUserssyncExistingParticipantshasSubscribedTrackssetupRoomListenerssetupParticipantListenerscreateMediaStatebroadcastMediaStateloadAudioSettingsgetSelectedDevicesupdateInputDeviceupdateOutputDeviceupdateVideoDeviceenableE2EEdisableE2EEonoffemitisConnectedgetCurrentChannelIdgetStats
Properties:
roomchannelIdcurrentUserIdroomTyperemoteServerDomainchannelsstatelocalMediaStateuserIdisAudioEnabledisVideoEnabledisScreenSharingisMutedisDeafenedisSpeakingaudioLevelstatesallUserStatescontrolremoteMicAudioElementsremoteScreenShareAudioElements100userMicVolumesuserScreenShareVolumesstreamQualitySettingsresolutionframeRateaudioBitratelistenerseventListenerssettingsaudioConstraintsechoCancellationnoiseSuppressionautoGainControlselectionselectedInputDeviceselectedOutputDeviceselectedVideoDeviceprovidere2eeKeyProvidercacheconfigCacheconfigCacheTimeCONFIG_CACHE_TTLminutevaluewidthheight3604807201080maxdefaultCONFIGURATIONbackendnowvalidresponseconfigenabledmodewsUrlallowFederatedVoiceavailableMANAGEMENTdatamethodheadersbodyerrorinstanceinstanceUrlactorIdroomNameTODOSFUchannelcancellationconnectioncleanupnulldomaintypetokenResponsetokenoptionsadaptiveStreamdynacaste2eeserverpromptanywayautoSubscribertcConfigiceTransportPolicyconnectingparticipantstrackcheckonesuserstruefalseURLwsUrlParsedoldChannelIdCONTROLSaudioTrackdeviceIdaudioBitrateBpsdtxredbitrateneededmuteaudioactivevideoTrackfacingModeconstraintvideoCodecsimulcastvideovideoPublicationcamerasharescreensharemutedscreenResolutiontargetFrameRateaudioBitrateKbpscaptureOptionsIMPORTANTnormalizationcapturecontentHintsystemAudiopublishOptionsvideoEncodingmaxBitrate1_500_000maxFrameratesecondscreenShareAudioBitrateitactualSettingsdisplaySurfacedebuggingpublishedVideocapturedhasScreenShareAudioAudioreasonsdisablingaudioPublicationchangeavoidCONTROLtrackscreationupdatedtrackCountcontinueconstraintsideal16framerateapplyingNotesavedlocalStoragevolumeclampedVolumeexistsidentityaudioElementmapelementundefinedACCESSstreamparticipantfederatedconsumedvideoElementattachVideoToElementlocalParticipantationsationstreamingseenresultHANDLINGNOTEexistingParticipantsUUIDmediaStatetotalthemimmediatelylaterhasSubscribedTracksreactivitytrackedchangesconnectedlookupsoperationsdisconnectedminimumkeysourcesubscribedonlylookupIdTrackSubscribedisScreenShareAudiofirstexistingElementsavedVolumeunsubscribedreferencesdetachkeysendinglookupspeakerIdentitiesduplicatesprocessedUserIds50leveleventsDisconnectedErrormessageunpublishedflagunpublishunmutedchangedspeakingresolvedUserIdmicrophonehasMicisMicMutedbreakencoderreliableVoiceSettingsServicedevicesinputDeviceoutputDevicevideoDevicedevicetooutputE2EESYSTEMeventcallbackindexlistenerMETHODSIDstatisticsnumParticipantsconnectionQuality
Interfaces
UserMediaState
No description available.
typescript
interface UserMediaState {
userId: string;
isAudioEnabled: boolean;
isVideoEnabled: boolean;
isScreenSharing: boolean;
isMuted: boolean;
isDeafened: boolean;
isSpeaking: boolean;
audioLevel: number;
}LiveKitConfig
No description available.
typescript
interface LiveKitConfig {
enabled: boolean;
mode: 'sfu' | 'p2p' | 'hybrid';
wsUrl: string | null;
allowFederatedVoice: boolean;
}TokenResponse
No description available.
typescript
interface TokenResponse {
token: string;
wsUrl: string;
roomName: string;
identity: string;
}Source Code Insights
File Size: 80933 characters Lines of Code: 2178 Imports: 5
Usage Example
typescript
import { UserMediaState, LiveKitConfig, LiveKitWebRTCService, livekitWebRTC } from '@/services/livekitWebRTC'
// Example usage
resolveIdentityToUuid()This documentation was automatically generated from the source code.
