UNPKG

@huddle01/web-core

Version:

The Huddle01 Javascript SDK offers a comprehensive suite of methods and event listeners that allow for seamless real-time audio and video communication with minimal coding required.

174 lines (171 loc) 4.98 kB
import Consumer from './Consumer.js'; import { EnhancedEventEmitter } from './common-js/EnhancedEventEmitter.js'; import { TPermissions } from 'types/dist/common.types'; import 'mediasoup-client/lib/types'; import 'mediasoup-client/lib/RtpParameters'; type RemotePeerEvents = { 'stream-available': [ data: { label: string; labelData: { producerId: string; }; } ]; 'stream-playable': [ data: { label: string; consumer: Consumer; } ]; 'stream-closed': [ data: { label: string; reason?: { code: number; tag: string; message: string; }; } ]; 'stream-paused': [ data: { label: string; producerId: string; peerId: string; } ]; 'metadata-updated': [ data: { metadata: string; } ]; 'role-updated': [ data: { role?: string; } ]; }; declare class RemotePeer extends EnhancedEventEmitter<RemotePeerEvents> { /** * peerId of the remote peer, this is unique for each peer */ peerId: string; /** * Stores the Metadata for the Remote Peer. */ private __metadata; /** * Stores the Role of the Remote Peer. */ private __role; /** * Labels are the unique identifier for the media stream that the remote peer is producing */ private readonly __labelsToProducerId; /** * Returns the list of labels that the remote peer is producing */ get labels(): string[]; get producerIds(): string[]; /** * Role of the Peer. * @returns The Role of the Peer which if passed in the options when creating the token */ get role(): string | null; set role(role: string); /** * Checks if the remote peer is producing the label * @param label - Label to check if the remote peer is producing * @returns - Returns true if the remote peer is producing the label */ hasLabel(label: string): boolean; /** * Returns the data associated to the label, this is the producerId * * @returns * producerId - Unique identifier for the producer */ getLabelData(label: string): { producerId: string; } | undefined; /** * Get the associated consumer for the label * @param label - Unique identifier for the consumer e.g. `video` | `audio` | `screen-share-video` | string * @returns Consumer | null */ getConsumer(label: string): Consumer | null; /** * Returns the metadata associated to the RemotePeer */ getMetadata<T = unknown>(): T; /** * Setter function to update the Remote Peer Metadata * * `NOTE: This will NOT notify other Remote Peers of the update` */ set metadata(data: string); /** * Update the Permissions of the Remote Peer in the Room. This will emit an event `updated` with the updated permissions. */ updatePermissions: (data: Partial<{ admin: boolean; canConsume: boolean; canProduce: boolean; canProduceSources: { cam: boolean; mic: boolean; screen: boolean; }; canSendData: boolean; canRecvData: boolean; canUpdateMetadata: boolean; }>) => Promise<void>; /** * Update the role of the Remote Peer in the Room, this will emit an event `updated` with the updated role. * @throws { Error } If the Peer Calling this function is not an `admin` then it will throw an error. */ updateRole: (data: { role: string; options?: { custom: TPermissions; }; }) => Promise<void>; /** * Removes all the states of the remote peer and clears memory; * * `NOTE`: You need to close consumers using the `recvTransport.closeConsumer` of the local peer */ close: () => void; constructor(data: { peerId: string; metadata?: string; role?: string; }); /** * @protected * Add a New Label to the Remote Peer and associate it with the ProducerId * * `NOTE: This is used internally by the Peer` * * @param data - Data to add the new label `label` and the `producerId` to associate it with */ _addLabelData: (data: { label: string; producerId: string; }) => Promise<void>; /** * @protected * Remove a Label from the Remote Peer and emit a `stream-closed` event * * `NOTE: This is used internally by the Peer` * * @param data - Data to remove the label from the Remote Peer */ _removeLabelData: (label: string, reason?: { code: number; tag: string; message: string; }) => void; } export { type RemotePeerEvents, RemotePeer as default };