livekit-client
Version:
JavaScript/TypeScript client SDK for LiveKit
104 lines • 5.59 kB
TypeScript
import type { Throws } from '@livekit/throws-transformer/throws';
import type TypedEmitter from 'typed-emitter';
import type { BaseE2EEManager } from '../../../e2ee/E2eeManager';
import type Participant from '../../participant/Participant';
import type RemoteParticipant from '../../participant/RemoteParticipant';
import { DataTrackDepacketizerDropError } from '../depacketizer';
import { type DataTrackFrame } from '../frame';
import { DataTrackHandle } from '../handle';
import { type DataTrackInfo, type DataTrackSid } from '../types';
import { DataTrackSubscribeError } from './errors';
import { type EventSfuUpdateSubscription, type EventTrackAvailable, type EventTrackUnavailable } from './types';
export type DataTrackIncomingManagerCallbacks = {
/** Request sent to the SFU to update the subscription for a data track. */
sfuUpdateSubscription: (event: EventSfuUpdateSubscription) => void;
/** A track has been published by a remote participant and is available to be
* subscribed to. */
trackPublished: (event: EventTrackAvailable) => void;
/** A track has been unpublished by a remote participant and can no longer be subscribed to. */
trackUnpublished: (event: EventTrackUnavailable) => void;
};
type IncomingDataTrackManagerOptions = {
/** Provider to use for decrypting incoming frame payloads.
* If none, remote tracks using end-to-end encryption will not be available
* for subscription.
*/
e2eeManager?: BaseE2EEManager;
};
declare const IncomingDataTrackManager_base: new () => TypedEmitter<DataTrackIncomingManagerCallbacks>;
export default class IncomingDataTrackManager extends IncomingDataTrackManager_base {
private e2eeManager;
/** Mapping between track SID and descriptor. */
private descriptors;
/** Mapping between subscriber handle and track SID.
*
* This is an index that allows track descriptors to be looked up
* by subscriber handle in O(1) time, to make routing incoming packets
* a (hot code path) faster.
*/
private subscriptionHandles;
constructor(options?: IncomingDataTrackManagerOptions);
/** @internal */
updateE2eeManager(e2eeManager: BaseE2EEManager | null): void;
/** Allocates a ReadableStream which emits when a new {@link DataTrackFrame} is received from the
* SFU. The SFU subscription is initiated lazily when the stream is created.
*
* @returns A tuple of the ReadableStream and a Promise that resolves once the SFU subscription
* is fully established / the stream is ready to receive frames.
*
* @internal
**/
openSubscriptionStream(sid: DataTrackSid, signal?: AbortSignal, bufferSize?: number): [ReadableStream<DataTrackFrame>, Promise<Throws<void, DataTrackSubscribeError>>];
/** Client requested to subscribe to a data track.
*
* This is sent when the user calls {@link RemoteDataTrack.subscribe}.
*
* Only the first request to subscribe to a given track incurs meaningful overhead; subsequent
* requests simply attach an additional receiver to the broadcast channel, allowing them to consume
* frames from the existing subscription pipeline.
*/
subscribeRequest(sid: DataTrackSid, signal?: AbortSignal): Promise<Throws<void, DataTrackSubscribeError>>;
/**
* Get information about all currently subscribed tracks.
* @internal */
querySubscribed(): Promise<[info: DataTrackInfo, identity: string][]>;
/** Client requested to unsubscribe from a data track. */
unSubscribeRequest(sid: DataTrackSid): void;
/** SFU notification that track publications have changed.
*
* This event is produced from both {@link JoinResponse} and {@link ParticipantUpdate}
* to provide a complete view of remote participants' track publications:
*
* - From a `JoinResponse`, it captures the initial set of tracks published when a participant joins.
* - From a `ParticipantUpdate`, it captures subsequent changes (i.e., new tracks being
* published and existing tracks unpublished).
*/
receiveSfuPublicationUpdates(updates: Map<Participant['identity'], Array<DataTrackInfo>>): Promise<void>;
/**
* Get information about all currently remotely published tracks which could be subscribed to.
* @internal */
queryPublications(): Promise<DataTrackInfo[]>;
handleTrackPublished(publisherIdentity: Participant['identity'], info: DataTrackInfo): Promise<void>;
handleTrackUnpublished(sid: DataTrackSid): void;
/** SFU notification that handles have been assigned for requested subscriptions. */
receivedSfuSubscriberHandles(
/** Mapping between track handles attached to incoming packets to the
* track SIDs they belong to. */
mapping: Map<DataTrackHandle, DataTrackSid>): void;
private registerSubscriberHandle;
/** Packet has been received over the transport. */
packetReceived(bytes: Uint8Array): Promise<Throws<void, DataTrackDepacketizerDropError>>;
/** Resend all subscription updates.
*
* This must be sent after a full reconnect to ensure the SFU knows which
* tracks are subscribed to locally.
*/
resendSubscriptionUpdates(): void;
/** Called when a remote participant is disconnected so that any pending data tracks can be
* cancelled. */
handleRemoteParticipantDisconnected(remoteParticipantIdentity: RemoteParticipant['identity']): void;
/** Shutdown the manager, ending any subscriptions. */
shutdown(): void;
}
export {};
//# sourceMappingURL=IncomingDataTrackManager.d.ts.map