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.

106 lines (103 loc) 2.71 kB
import { Room_default } from './chunk-5B3BC5M6.js'; import { mainLogger } from './chunk-TOCFOGTC.js'; import { EnhancedEventEmitter } from './chunk-BW2DGP4D.js'; // src/ActiveSpeakers.ts var logger = mainLogger.createSubLogger("ActiveSpeakers"); var ActiveSpeakers = class extends EnhancedEventEmitter { /** * Room instance. */ __room = Room_default.getInstance(); /** * Bot instance which has the data producer connected directly to the room bot. * This is used to handle all the states of the room and its functionality. */ __bot; /** * Is the notification active. */ __active; /** * Is the notification active. */ get active() { return this.__active; } /** * Maximum number of entries in the list. */ MAX_SIZE = 20; /** * Size by which the active speakers list will be notified. * `note: default size is 8` */ __size; /** * Size by which the active speakers list will be notified. */ get size() { return this.__size; } /** * Array of ActiveSpeakers ordered by volume. */ __activePeerIds = []; get activePeerIds() { return this.__activePeerIds; } /** * Update the number of peerIds to notify. * @param size */ updateSize = (size) => { logger.info("\u{1F514} Updating Active Speaker Size to", size); if (size > this.MAX_SIZE) { logger.error( "\u{1F514} Active Speaker Size cannot be greater than", this.MAX_SIZE ); return; } this.__size = size; }; /** * Handle all the events emitted by the bot. */ __handleBotEvents = () => { this.__bot.on("active-speakers-change", this.__handleActiveSpeakerChange); }; /** * Emit the active speakers change event. * @param data - Data containing the peerIds of the active speakers. */ __handleActiveSpeakerChange = (data) => { try { const { peerIds } = data; this.__activePeerIds = peerIds; const slicedPeerData = peerIds.slice(0, this.__size); this.__room.emit("active-speakers-change", { peerIds: slicedPeerData ?? [], dominantSpeaker: peerIds?.[0] ?? "" }); } catch (error) { logger.error("Error: Handling New Active Speakers Notification", error); logger.error(error); } }; constructor(data) { super(); this.__bot = data.bot; this.__size = data?.size ?? 8; this.__active = true; this.__handleBotEvents(); } /** * Close the active speakers instance. */ close = () => { this.__active = false; this.__bot.off("active-speakers-change", this.__handleActiveSpeakerChange); }; }; var ActiveSpeakers_default = ActiveSpeakers; export { ActiveSpeakers_default };