LiveKit JS Client SDK - v2.10.0

    Class Room

    In LiveKit, a room is the logical grouping for a list of participants. Participants in a room can publish tracks, and subscribe to others' tracks.

    a Room fires [[RoomEvent | RoomEvents]].

    Hierarchy

    • TypedEventEmitter<RoomEventCallbacks, this>
      • Room
    Index

    Constructors

    • Creates a new Room, the primary construct for a LiveKit session.

      Parameters

      Returns Room

    Properties

    activeSpeakers: Participant[] = []

    list of participants that are actively speaking. when this changes a [[RoomEvent.ActiveSpeakersChanged]] event is fired

    bufferedSegments: Map<string, TranscriptionSegment> = ...
    isE2EEEnabled: boolean = false

    reflects the sender encryption status of the local participant

    localParticipant: LocalParticipant

    the current participant

    options: InternalRoomOptions

    options of room

    remoteParticipants: Map<string, RemoteParticipant>

    map of identity: [[RemoteParticipant]]

    serverInfo?: Partial<ServerInfo>
    state: ConnectionState = ConnectionState.Disconnected
    cleanupRegistry: false | FinalizationRegistry<() => void> = ...

    Accessors

    • get canPlaybackAudio(): boolean

      Returns true if audio playback is enabled

      Returns boolean

    • get canPlaybackVideo(): boolean

      Returns true if video playback is enabled

      Returns boolean

    • get isRecording(): boolean

      if the current room has a participant with recorder: true in its JWT grant

      Returns boolean

    • get metadata(): undefined | string

      room metadata

      Returns undefined | string

    • get name(): string

      user assigned name, derived from JWT token

      Returns string

    Methods

    • disconnects the room, emits [[RoomEvent.Disconnected]]

      Parameters

      • stopTracks: boolean = true

      Returns Promise<void>

    • Type Parameters

      • E extends keyof RoomEventCallbacks

      Parameters

      • event: E
      • ...args: Parameters<RoomEventCallbacks[E]>

      Returns boolean

    • Parameters

      • kind: MediaDeviceKind

      Returns undefined | string

    • server assigned unique room id. returns once a sid has been issued by the server.

      Returns Promise<string>

    • prepareConnection should be called as soon as the page is loaded, in order to speed up the connection attempt. This function will

      • perform DNS resolution and pre-warm the DNS cache
      • establish TLS connection and cache TLS keys

      With LiveKit Cloud, it will also determine the best edge data center for the current client to connect to if a token is provided.

      Parameters

      • url: string
      • Optionaltoken: string

      Returns Promise<void>

    • Establishes the participant as a receiver for calls of the specified RPC method.

      Parameters

      • method: string

        The name of the indicated RPC method

      • handler: (data: RpcInvocationData) => Promise<string>

        Will be invoked when an RPC request for this method is received

      Returns void

      A promise that resolves when the method is successfully registered

      If a handler for this method is already registered (must call unregisterRpcMethod first)

      room.localParticipant?.registerRpcMethod(
      'greet',
      async (data: RpcInvocationData) => {
      console.log(`Received greeting from ${data.callerIdentity}: ${data.payload}`);
      return `Hello, ${data.callerIdentity}!`;
      }
      );

      The handler should return a Promise that resolves to a string. If unable to respond within responseTimeout, the request will result in an error on the caller's side.

      You may throw errors of type RpcError with a string message in the handler, and they will be received on the caller's side with the message intact. Other errors thrown in your handler will not be transmitted as-is, and will instead arrive to the caller as 1500 ("Application Error").

    • Experimental

      Parameters

      • enabled: boolean

      Returns Promise<void>

    • Experimental

      Allows to populate a room with simulated participants. No actual connection to a server will be established, all state is

      Parameters

      • options: SimulationOptions

      Returns Promise<void>

    • Browsers have different policies regarding audio playback. Most requiring some form of user interaction (click/tap/etc). In those cases, audio will be silent until a click/tap triggering one of the following

      • startAudio
      • getUserMedia

      Returns Promise<void>

    • Switches all active devices used in this room to the given device.

      Note: setting AudioOutput is not supported on some browsers. See setSinkId

      Parameters

      • kind: MediaDeviceKind

        use videoinput for camera track, audioinput for microphone track, audiooutput to set speaker for all incoming audio tracks

      • deviceId: string
      • exact: boolean = false

      Returns Promise<boolean>

    • Parameters

      • topic: string

      Returns void

    • Unregisters a previously registered RPC method.

      Parameters

      • method: string

        The name of the RPC method to unregister

      Returns void

    • Parameters

      • topic: string

      Returns void

    • getLocalDevices abstracts navigator.mediaDevices.enumerateDevices. In particular, it requests device permissions by default if needed and makes sure the returned device does not consist of dummy devices

      Parameters

      • Optionalkind: MediaDeviceKind
      • requestPermissions: boolean = true

      Returns Promise<MediaDeviceInfo[]>

      a list of available local devices

    MMNEPVFCICPMFPCPTTAAATR