You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

external_api.js 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  1. import { jitsiLocalStorage } from '@jitsi/js-utils/jitsi-local-storage';
  2. import EventEmitter from 'events';
  3. import { urlObjectToString } from '../../../react/features/base/util/uri';
  4. import {
  5. PostMessageTransportBackend,
  6. Transport
  7. } from '../../transport';
  8. import {
  9. getAvailableDevices,
  10. getCurrentDevices,
  11. isDeviceChangeAvailable,
  12. isDeviceListAvailable,
  13. isMultipleAudioInputSupported,
  14. setAudioInputDevice,
  15. setAudioOutputDevice,
  16. setVideoInputDevice
  17. } from './functions';
  18. const ALWAYS_ON_TOP_FILENAMES = [
  19. 'css/all.css', 'libs/alwaysontop.min.js'
  20. ];
  21. /**
  22. * Maps the names of the commands expected by the API with the name of the
  23. * commands expected by jitsi-meet.
  24. */
  25. const commands = {
  26. addBreakoutRoom: 'add-breakout-room',
  27. answerKnockingParticipant: 'answer-knocking-participant',
  28. approveVideo: 'approve-video',
  29. askToUnmute: 'ask-to-unmute',
  30. autoAssignToBreakoutRooms: 'auto-assign-to-breakout-rooms',
  31. avatarUrl: 'avatar-url',
  32. cancelPrivateChat: 'cancel-private-chat',
  33. closeBreakoutRoom: 'close-breakout-room',
  34. displayName: 'display-name',
  35. e2eeKey: 'e2ee-key',
  36. endConference: 'end-conference',
  37. email: 'email',
  38. grantModerator: 'grant-moderator',
  39. hangup: 'video-hangup',
  40. hideNotification: 'hide-notification',
  41. initiatePrivateChat: 'initiate-private-chat',
  42. joinBreakoutRoom: 'join-breakout-room',
  43. localSubject: 'local-subject',
  44. kickParticipant: 'kick-participant',
  45. muteEveryone: 'mute-everyone',
  46. overwriteConfig: 'overwrite-config',
  47. overwriteNames: 'overwrite-names',
  48. password: 'password',
  49. pinParticipant: 'pin-participant',
  50. rejectParticipant: 'reject-participant',
  51. removeBreakoutRoom: 'remove-breakout-room',
  52. resizeFilmStrip: 'resize-film-strip',
  53. resizeLargeVideo: 'resize-large-video',
  54. sendChatMessage: 'send-chat-message',
  55. sendEndpointTextMessage: 'send-endpoint-text-message',
  56. sendParticipantToRoom: 'send-participant-to-room',
  57. sendTones: 'send-tones',
  58. setAssumedBandwidthBps: 'set-assumed-bandwidth-bps',
  59. setFollowMe: 'set-follow-me',
  60. setLargeVideoParticipant: 'set-large-video-participant',
  61. setMediaEncryptionKey: 'set-media-encryption-key',
  62. setNoiseSuppressionEnabled: 'set-noise-suppression-enabled',
  63. setParticipantVolume: 'set-participant-volume',
  64. setSubtitles: 'set-subtitles',
  65. setTileView: 'set-tile-view',
  66. setVideoQuality: 'set-video-quality',
  67. showNotification: 'show-notification',
  68. startRecording: 'start-recording',
  69. startShareVideo: 'start-share-video',
  70. stopRecording: 'stop-recording',
  71. stopShareVideo: 'stop-share-video',
  72. subject: 'subject',
  73. submitFeedback: 'submit-feedback',
  74. toggleAudio: 'toggle-audio',
  75. toggleCamera: 'toggle-camera',
  76. toggleCameraMirror: 'toggle-camera-mirror',
  77. toggleChat: 'toggle-chat',
  78. toggleE2EE: 'toggle-e2ee',
  79. toggleFilmStrip: 'toggle-film-strip',
  80. toggleLobby: 'toggle-lobby',
  81. toggleModeration: 'toggle-moderation',
  82. toggleNoiseSuppression: 'toggle-noise-suppression',
  83. toggleParticipantsPane: 'toggle-participants-pane',
  84. toggleRaiseHand: 'toggle-raise-hand',
  85. toggleShareScreen: 'toggle-share-screen',
  86. toggleSubtitles: 'toggle-subtitles',
  87. toggleTileView: 'toggle-tile-view',
  88. toggleVirtualBackgroundDialog: 'toggle-virtual-background',
  89. toggleVideo: 'toggle-video',
  90. toggleWhiteboard: 'toggle-whiteboard'
  91. };
  92. /**
  93. * Maps the names of the events expected by the API with the name of the
  94. * events expected by jitsi-meet.
  95. */
  96. const events = {
  97. 'avatar-changed': 'avatarChanged',
  98. 'audio-availability-changed': 'audioAvailabilityChanged',
  99. 'audio-mute-status-changed': 'audioMuteStatusChanged',
  100. 'audio-or-video-sharing-toggled': 'audioOrVideoSharingToggled',
  101. 'breakout-rooms-updated': 'breakoutRoomsUpdated',
  102. 'browser-support': 'browserSupport',
  103. 'camera-error': 'cameraError',
  104. 'chat-updated': 'chatUpdated',
  105. 'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
  106. 'data-channel-closed': 'dataChannelClosed',
  107. 'data-channel-opened': 'dataChannelOpened',
  108. 'device-list-changed': 'deviceListChanged',
  109. 'display-name-change': 'displayNameChange',
  110. 'email-change': 'emailChange',
  111. 'error-occurred': 'errorOccurred',
  112. 'endpoint-text-message-received': 'endpointTextMessageReceived',
  113. 'face-landmark-detected': 'faceLandmarkDetected',
  114. 'feedback-submitted': 'feedbackSubmitted',
  115. 'feedback-prompt-displayed': 'feedbackPromptDisplayed',
  116. 'filmstrip-display-changed': 'filmstripDisplayChanged',
  117. 'incoming-message': 'incomingMessage',
  118. 'knocking-participant': 'knockingParticipant',
  119. 'log': 'log',
  120. 'mic-error': 'micError',
  121. 'moderation-participant-approved': 'moderationParticipantApproved',
  122. 'moderation-participant-rejected': 'moderationParticipantRejected',
  123. 'moderation-status-changed': 'moderationStatusChanged',
  124. 'mouse-enter': 'mouseEnter',
  125. 'mouse-leave': 'mouseLeave',
  126. 'mouse-move': 'mouseMove',
  127. 'notification-triggered': 'notificationTriggered',
  128. 'outgoing-message': 'outgoingMessage',
  129. 'participant-joined': 'participantJoined',
  130. 'participant-kicked-out': 'participantKickedOut',
  131. 'participant-left': 'participantLeft',
  132. 'participant-role-changed': 'participantRoleChanged',
  133. 'participants-pane-toggled': 'participantsPaneToggled',
  134. 'password-required': 'passwordRequired',
  135. 'peer-connection-failure': 'peerConnectionFailure',
  136. 'prejoin-screen-loaded': 'prejoinScreenLoaded',
  137. 'proxy-connection-event': 'proxyConnectionEvent',
  138. 'raise-hand-updated': 'raiseHandUpdated',
  139. 'recording-link-available': 'recordingLinkAvailable',
  140. 'recording-status-changed': 'recordingStatusChanged',
  141. 'participant-menu-button-clicked': 'participantMenuButtonClick',
  142. 'video-ready-to-close': 'readyToClose',
  143. 'video-conference-joined': 'videoConferenceJoined',
  144. 'video-conference-left': 'videoConferenceLeft',
  145. 'video-availability-changed': 'videoAvailabilityChanged',
  146. 'video-mute-status-changed': 'videoMuteStatusChanged',
  147. 'video-quality-changed': 'videoQualityChanged',
  148. 'screen-sharing-status-changed': 'screenSharingStatusChanged',
  149. 'dominant-speaker-changed': 'dominantSpeakerChanged',
  150. 'subject-change': 'subjectChange',
  151. 'suspend-detected': 'suspendDetected',
  152. 'tile-view-changed': 'tileViewChanged',
  153. 'toolbar-button-clicked': 'toolbarButtonClicked',
  154. 'whiteboard-status-changed': 'whiteboardStatusChanged'
  155. };
  156. /**
  157. * Last id of api object.
  158. *
  159. * @type {number}
  160. */
  161. let id = 0;
  162. /**
  163. * Adds given number to the numberOfParticipants property of given APIInstance.
  164. *
  165. * @param {JitsiMeetExternalAPI} APIInstance - The instance of the API.
  166. * @param {int} number - The number of participants to be added to
  167. * numberOfParticipants property (this parameter can be negative number if the
  168. * numberOfParticipants should be decreased).
  169. * @returns {void}
  170. */
  171. function changeParticipantNumber(APIInstance, number) {
  172. APIInstance._numberOfParticipants += number;
  173. }
  174. /**
  175. * Generates the URL for the iframe.
  176. *
  177. * @param {string} domain - The domain name of the server that hosts the
  178. * conference.
  179. * @param {string} [options] - Another optional parameters.
  180. * @param {Object} [options.configOverwrite] - Object containing configuration
  181. * options defined in config.js to be overridden.
  182. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  183. * configuration options defined in interface_config.js to be overridden.
  184. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  185. * authentication.
  186. * @param {string} [options.lang] - The meeting's default language.
  187. * @param {string} [options.roomName] - The name of the room to join.
  188. * @returns {string} The URL.
  189. */
  190. function generateURL(domain, options = {}) {
  191. return urlObjectToString({
  192. ...options,
  193. url: `https://${domain}/#jitsi_meet_external_api_id=${id}`
  194. });
  195. }
  196. /**
  197. * Parses the arguments passed to the constructor. If the old format is used
  198. * the function translates the arguments to the new format.
  199. *
  200. * @param {Array} args - The arguments to be parsed.
  201. * @returns {Object} JS object with properties.
  202. */
  203. function parseArguments(args) {
  204. if (!args.length) {
  205. return {};
  206. }
  207. const firstArg = args[0];
  208. switch (typeof firstArg) {
  209. case 'string': // old arguments format
  210. case 'undefined': {
  211. // Not sure which format but we are trying to parse the old
  212. // format because if the new format is used everything will be undefined
  213. // anyway.
  214. const [
  215. roomName,
  216. width,
  217. height,
  218. parentNode,
  219. configOverwrite,
  220. interfaceConfigOverwrite,
  221. jwt,
  222. onload,
  223. lang
  224. ] = args;
  225. return {
  226. roomName,
  227. width,
  228. height,
  229. parentNode,
  230. configOverwrite,
  231. interfaceConfigOverwrite,
  232. jwt,
  233. onload,
  234. lang
  235. };
  236. }
  237. case 'object': // new arguments format
  238. return args[0];
  239. default:
  240. throw new Error('Can\'t parse the arguments!');
  241. }
  242. }
  243. /**
  244. * Compute valid values for height and width. If a number is specified it's
  245. * treated as pixel units. If the value is expressed in px, em, pt or
  246. * percentage, it's used as is.
  247. *
  248. * @param {any} value - The value to be parsed.
  249. * @returns {string|undefined} The parsed value that can be used for setting
  250. * sizes through the style property. If invalid value is passed the method
  251. * returns undefined.
  252. */
  253. function parseSizeParam(value) {
  254. let parsedValue;
  255. // This regex parses values of the form 100px, 100em, 100pt or 100%.
  256. // Values like 100 or 100px are handled outside of the regex, and
  257. // invalid values will be ignored and the minimum will be used.
  258. const re = /([0-9]*\.?[0-9]+)(em|pt|px|%)$/;
  259. if (typeof value === 'string' && String(value).match(re) !== null) {
  260. parsedValue = value;
  261. } else if (typeof value === 'number') {
  262. parsedValue = `${value}px`;
  263. }
  264. return parsedValue;
  265. }
  266. /**
  267. * The IFrame API interface class.
  268. */
  269. export default class JitsiMeetExternalAPI extends EventEmitter {
  270. /**
  271. * Constructs new API instance. Creates iframe and loads Jitsi Meet in it.
  272. *
  273. * @param {string} domain - The domain name of the server that hosts the
  274. * conference.
  275. * @param {Object} [options] - Optional arguments.
  276. * @param {string} [options.roomName] - The name of the room to join.
  277. * @param {number|string} [options.width] - Width of the iframe. Check
  278. * parseSizeParam for format details.
  279. * @param {number|string} [options.height] - Height of the iframe. Check
  280. * parseSizeParam for format details.
  281. * @param {DOMElement} [options.parentNode] - The node that will contain the
  282. * iframe.
  283. * @param {Object} [options.configOverwrite] - Object containing
  284. * configuration options defined in config.js to be overridden.
  285. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  286. * configuration options defined in interface_config.js to be overridden.
  287. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  288. * authentication.
  289. * @param {string} [options.lang] - The meeting's default language.
  290. * @param {string} [options.onload] - The onload function that will listen
  291. * for iframe onload event.
  292. * @param {Array<Object>} [options.invitees] - Array of objects containing
  293. * information about new participants that will be invited in the call.
  294. * @param {Array<Object>} [options.devices] - Array of objects containing
  295. * information about the initial devices that will be used in the call.
  296. * @param {Object} [options.userInfo] - Object containing information about
  297. * the participant opening the meeting.
  298. * @param {string} [options.e2eeKey] - The key used for End-to-End encryption.
  299. * THIS IS EXPERIMENTAL.
  300. * @param {string} [options.release] - The key used for specifying release if enabled on the backend.
  301. */
  302. constructor(domain, ...args) {
  303. super();
  304. const {
  305. roomName = '',
  306. width = '100%',
  307. height = '100%',
  308. parentNode = document.body,
  309. configOverwrite = {},
  310. interfaceConfigOverwrite = {},
  311. jwt = undefined,
  312. lang = undefined,
  313. onload = undefined,
  314. invitees,
  315. devices,
  316. userInfo,
  317. e2eeKey,
  318. release
  319. } = parseArguments(args);
  320. const localStorageContent = jitsiLocalStorage.getItem('jitsiLocalStorage');
  321. this._parentNode = parentNode;
  322. this._url = generateURL(domain, {
  323. configOverwrite,
  324. interfaceConfigOverwrite,
  325. jwt,
  326. lang,
  327. roomName,
  328. devices,
  329. userInfo,
  330. appData: {
  331. localStorageContent
  332. },
  333. release
  334. });
  335. this._createIFrame(height, width, onload);
  336. this._transport = new Transport({
  337. backend: new PostMessageTransportBackend({
  338. postisOptions: {
  339. allowedOrigin: new URL(this._url).origin,
  340. scope: `jitsi_meet_external_api_${id}`,
  341. window: this._frame.contentWindow
  342. }
  343. })
  344. });
  345. if (Array.isArray(invitees) && invitees.length > 0) {
  346. this.invite(invitees);
  347. }
  348. this._tmpE2EEKey = e2eeKey;
  349. this._isLargeVideoVisible = false;
  350. this._isPrejoinVideoVisible = false;
  351. this._numberOfParticipants = 0;
  352. this._participants = {};
  353. this._myUserID = undefined;
  354. this._onStageParticipant = undefined;
  355. this._setupListeners();
  356. id++;
  357. }
  358. /**
  359. * Creates the iframe element.
  360. *
  361. * @param {number|string} height - The height of the iframe. Check
  362. * parseSizeParam for format details.
  363. * @param {number|string} width - The with of the iframe. Check
  364. * parseSizeParam for format details.
  365. * @param {Function} onload - The function that will listen
  366. * for onload event.
  367. * @returns {void}
  368. *
  369. * @private
  370. */
  371. _createIFrame(height, width, onload) {
  372. const frameName = `jitsiConferenceFrame${id}`;
  373. this._frame = document.createElement('iframe');
  374. this._frame.allow = 'camera; microphone; display-capture; autoplay; clipboard-write; hid';
  375. this._frame.name = frameName;
  376. this._frame.id = frameName;
  377. this._setSize(height, width);
  378. this._frame.setAttribute('allowFullScreen', 'true');
  379. this._frame.style.border = 0;
  380. if (onload) {
  381. // waits for iframe resources to load
  382. // and fires event when it is done
  383. this._frame.onload = onload;
  384. }
  385. this._frame.src = this._url;
  386. this._frame = this._parentNode.appendChild(this._frame);
  387. }
  388. /**
  389. * Returns arrays with the all resources for the always on top feature.
  390. *
  391. * @returns {Array<string>}
  392. */
  393. _getAlwaysOnTopResources() {
  394. const iframeWindow = this._frame.contentWindow;
  395. const iframeDocument = iframeWindow.document;
  396. let baseURL = '';
  397. const base = iframeDocument.querySelector('base');
  398. if (base && base.href) {
  399. baseURL = base.href;
  400. } else {
  401. const { protocol, host } = iframeWindow.location;
  402. baseURL = `${protocol}//${host}`;
  403. }
  404. return ALWAYS_ON_TOP_FILENAMES.map(
  405. filename => new URL(filename, baseURL).href
  406. );
  407. }
  408. /**
  409. * Returns the formatted display name of a participant.
  410. *
  411. * @param {string} participantId - The id of the participant.
  412. * @returns {string} The formatted display name.
  413. */
  414. _getFormattedDisplayName(participantId) {
  415. const { formattedDisplayName }
  416. = this._participants[participantId] || {};
  417. return formattedDisplayName;
  418. }
  419. /**
  420. * Returns the id of the on stage participant.
  421. *
  422. * @returns {string} - The id of the on stage participant.
  423. */
  424. _getOnStageParticipant() {
  425. return this._onStageParticipant;
  426. }
  427. /**
  428. * Getter for the large video element in Jitsi Meet.
  429. *
  430. * @returns {HTMLElement|undefined} - The large video.
  431. */
  432. _getLargeVideo() {
  433. const iframe = this.getIFrame();
  434. if (!this._isLargeVideoVisible
  435. || !iframe
  436. || !iframe.contentWindow
  437. || !iframe.contentWindow.document) {
  438. return;
  439. }
  440. return iframe.contentWindow.document.getElementById('largeVideo');
  441. }
  442. /**
  443. * Getter for the prejoin video element in Jitsi Meet.
  444. *
  445. * @returns {HTMLElement|undefined} - The prejoin video.
  446. */
  447. _getPrejoinVideo() {
  448. const iframe = this.getIFrame();
  449. if (!this._isPrejoinVideoVisible
  450. || !iframe
  451. || !iframe.contentWindow
  452. || !iframe.contentWindow.document) {
  453. return;
  454. }
  455. return iframe.contentWindow.document.getElementById('prejoinVideo');
  456. }
  457. /**
  458. * Getter for participant specific video element in Jitsi Meet.
  459. *
  460. * @param {string|undefined} participantId - Id of participant to return the video for.
  461. *
  462. * @returns {HTMLElement|undefined} - The requested video. Will return the local video
  463. * by default if participantId is undefined.
  464. */
  465. _getParticipantVideo(participantId) {
  466. const iframe = this.getIFrame();
  467. if (!iframe
  468. || !iframe.contentWindow
  469. || !iframe.contentWindow.document) {
  470. return;
  471. }
  472. if (typeof participantId === 'undefined' || participantId === this._myUserID) {
  473. return iframe.contentWindow.document.getElementById('localVideo_container');
  474. }
  475. return iframe.contentWindow.document.querySelector(`#participant_${participantId} video`);
  476. }
  477. /**
  478. * Sets the size of the iframe element.
  479. *
  480. * @param {number|string} height - The height of the iframe.
  481. * @param {number|string} width - The with of the iframe.
  482. * @returns {void}
  483. *
  484. * @private
  485. */
  486. _setSize(height, width) {
  487. const parsedHeight = parseSizeParam(height);
  488. const parsedWidth = parseSizeParam(width);
  489. if (parsedHeight !== undefined) {
  490. this._height = height;
  491. this._frame.style.height = parsedHeight;
  492. }
  493. if (parsedWidth !== undefined) {
  494. this._width = width;
  495. this._frame.style.width = parsedWidth;
  496. }
  497. }
  498. /**
  499. * Setups listeners that are used internally for JitsiMeetExternalAPI.
  500. *
  501. * @returns {void}
  502. *
  503. * @private
  504. */
  505. _setupListeners() {
  506. this._transport.on('event', ({ name, ...data }) => {
  507. const userID = data.id;
  508. switch (name) {
  509. case 'video-conference-joined': {
  510. if (typeof this._tmpE2EEKey !== 'undefined') {
  511. this.executeCommand(commands.e2eeKey, this._tmpE2EEKey);
  512. this._tmpE2EEKey = undefined;
  513. }
  514. this._myUserID = userID;
  515. this._participants[userID] = {
  516. email: data.email,
  517. avatarURL: data.avatarURL
  518. };
  519. }
  520. // eslint-disable-next-line no-fallthrough
  521. case 'participant-joined': {
  522. this._participants[userID] = this._participants[userID] || {};
  523. this._participants[userID].displayName = data.displayName;
  524. this._participants[userID].formattedDisplayName
  525. = data.formattedDisplayName;
  526. changeParticipantNumber(this, 1);
  527. break;
  528. }
  529. case 'participant-left':
  530. changeParticipantNumber(this, -1);
  531. delete this._participants[userID];
  532. break;
  533. case 'display-name-change': {
  534. const user = this._participants[userID];
  535. if (user) {
  536. user.displayName = data.displayname;
  537. user.formattedDisplayName = data.formattedDisplayName;
  538. }
  539. break;
  540. }
  541. case 'email-change': {
  542. const user = this._participants[userID];
  543. if (user) {
  544. user.email = data.email;
  545. }
  546. break;
  547. }
  548. case 'avatar-changed': {
  549. const user = this._participants[userID];
  550. if (user) {
  551. user.avatarURL = data.avatarURL;
  552. }
  553. break;
  554. }
  555. case 'on-stage-participant-changed':
  556. this._onStageParticipant = userID;
  557. this.emit('largeVideoChanged');
  558. break;
  559. case 'large-video-visibility-changed':
  560. this._isLargeVideoVisible = data.isVisible;
  561. this.emit('largeVideoChanged');
  562. break;
  563. case 'prejoin-screen-loaded':
  564. this._participants[userID] = {
  565. displayName: data.displayName,
  566. formattedDisplayName: data.formattedDisplayName
  567. };
  568. break;
  569. case 'on-prejoin-video-changed':
  570. this._isPrejoinVideoVisible = data.isVisible;
  571. this.emit('prejoinVideoChanged');
  572. break;
  573. case 'video-conference-left':
  574. changeParticipantNumber(this, -1);
  575. delete this._participants[this._myUserID];
  576. break;
  577. case 'video-quality-changed':
  578. this._videoQuality = data.videoQuality;
  579. break;
  580. case 'breakout-rooms-updated':
  581. this.updateNumberOfParticipants(data.rooms);
  582. break;
  583. case 'local-storage-changed':
  584. jitsiLocalStorage.setItem('jitsiLocalStorage', data.localStorageContent);
  585. // Since this is internal event we don't need to emit it to the consumer of the API.
  586. return true;
  587. }
  588. const eventName = events[name];
  589. if (eventName) {
  590. this.emit(eventName, data);
  591. return true;
  592. }
  593. return false;
  594. });
  595. }
  596. /**
  597. * Update number of participants based on all rooms.
  598. *
  599. * @param {Object} rooms - Rooms available rooms in the conference.
  600. * @returns {void}
  601. */
  602. updateNumberOfParticipants(rooms) {
  603. if (!rooms || !Object.keys(rooms).length) {
  604. return;
  605. }
  606. const allParticipants = Object.keys(rooms).reduce((prev, roomItemKey) => {
  607. if (rooms[roomItemKey]?.participants) {
  608. return Object.keys(rooms[roomItemKey].participants).length + prev;
  609. }
  610. return prev;
  611. }, 0);
  612. this._numberOfParticipants = allParticipants;
  613. }
  614. /**
  615. * Returns the rooms info in the conference.
  616. *
  617. * @returns {Object} Rooms info.
  618. */
  619. async getRoomsInfo() {
  620. return this._transport.sendRequest({
  621. name: 'rooms-info'
  622. });
  623. }
  624. /**
  625. * Adds event listener to Meet Jitsi.
  626. *
  627. * @param {string} event - The name of the event.
  628. * @param {Function} listener - The listener.
  629. * @returns {void}
  630. *
  631. * @deprecated
  632. * NOTE: This method is not removed for backward comatability purposes.
  633. */
  634. addEventListener(event, listener) {
  635. this.on(event, listener);
  636. }
  637. /**
  638. * Adds event listeners to Meet Jitsi.
  639. *
  640. * @param {Object} listeners - The object key should be the name of
  641. * the event and value - the listener.
  642. * Currently we support the following
  643. * events:
  644. * {@code log} - receives event notifications whenever information has
  645. * been logged and has a log level specified within {@code config.apiLogLevels}.
  646. * The listener will receive object with the following structure:
  647. * {{
  648. * logLevel: the message log level
  649. * arguments: an array of strings that compose the actual log message
  650. * }}
  651. * {@code chatUpdated} - receives event notifications about chat state being
  652. * updated. The listener will receive object with the following structure:
  653. * {{
  654. * 'unreadCount': unreadCounter, // the unread message(s) counter,
  655. * 'isOpen': isOpen, // whether the chat panel is open or not
  656. * }}
  657. * {@code incomingMessage} - receives event notifications about incoming
  658. * messages. The listener will receive object with the following structure:
  659. * {{
  660. * 'from': from,//JID of the user that sent the message
  661. * 'nick': nick,//the nickname of the user that sent the message
  662. * 'message': txt//the text of the message
  663. * }}
  664. * {@code outgoingMessage} - receives event notifications about outgoing
  665. * messages. The listener will receive object with the following structure:
  666. * {{
  667. * 'message': txt//the text of the message
  668. * }}
  669. * {@code displayNameChanged} - receives event notifications about display
  670. * name change. The listener will receive object with the following
  671. * structure:
  672. * {{
  673. * jid: jid,//the JID of the participant that changed his display name
  674. * displayname: displayName //the new display name
  675. * }}
  676. * {@code participantJoined} - receives event notifications about new
  677. * participant.
  678. * The listener will receive object with the following structure:
  679. * {{
  680. * jid: jid //the jid of the participant
  681. * }}
  682. * {@code participantLeft} - receives event notifications about the
  683. * participant that left the room.
  684. * The listener will receive object with the following structure:
  685. * {{
  686. * jid: jid //the jid of the participant
  687. * }}
  688. * {@code videoConferenceJoined} - receives event notifications about the
  689. * local user has successfully joined the video conference.
  690. * The listener will receive object with the following structure:
  691. * {{
  692. * roomName: room //the room name of the conference
  693. * }}
  694. * {@code videoConferenceLeft} - receives event notifications about the
  695. * local user has left the video conference.
  696. * The listener will receive object with the following structure:
  697. * {{
  698. * roomName: room //the room name of the conference
  699. * }}
  700. * {@code screenSharingStatusChanged} - receives event notifications about
  701. * turning on/off the local user screen sharing.
  702. * The listener will receive object with the following structure:
  703. * {{
  704. * on: on //whether screen sharing is on
  705. * }}
  706. * {@code dominantSpeakerChanged} - receives event notifications about
  707. * change in the dominant speaker.
  708. * The listener will receive object with the following structure:
  709. * {{
  710. * id: participantId //participantId of the new dominant speaker
  711. * }}
  712. * {@code suspendDetected} - receives event notifications about detecting suspend event in host computer.
  713. * {@code readyToClose} - all hangup operations are completed and Jitsi Meet
  714. * is ready to be disposed.
  715. * @returns {void}
  716. *
  717. * @deprecated
  718. * NOTE: This method is not removed for backward comatability purposes.
  719. */
  720. addEventListeners(listeners) {
  721. for (const event in listeners) { // eslint-disable-line guard-for-in
  722. this.addEventListener(event, listeners[event]);
  723. }
  724. }
  725. /**
  726. * Captures the screenshot of the large video.
  727. *
  728. * @returns {Promise<string>} - Resolves with a base64 encoded image data of the screenshot
  729. * if large video is detected, an error otherwise.
  730. */
  731. captureLargeVideoScreenshot() {
  732. return this._transport.sendRequest({
  733. name: 'capture-largevideo-screenshot'
  734. });
  735. }
  736. /**
  737. * Removes the listeners and removes the Jitsi Meet frame.
  738. *
  739. * @returns {void}
  740. */
  741. dispose() {
  742. this.emit('_willDispose');
  743. this._transport.dispose();
  744. this.removeAllListeners();
  745. if (this._frame && this._frame.parentNode) {
  746. this._frame.parentNode.removeChild(this._frame);
  747. }
  748. }
  749. /**
  750. * Executes command. The available commands are:
  751. * {@code displayName} - Sets the display name of the local participant to
  752. * the value passed in the arguments array.
  753. * {@code subject} - Sets the subject of the conference, the value passed
  754. * in the arguments array. Note: Available only for moderator.
  755. *
  756. * {@code toggleAudio} - Mutes / unmutes audio with no arguments.
  757. * {@code toggleVideo} - Mutes / unmutes video with no arguments.
  758. * {@code toggleFilmStrip} - Hides / shows the filmstrip with no arguments.
  759. *
  760. * If the command doesn't require any arguments the parameter should be set
  761. * to empty array or it may be omitted.
  762. *
  763. * @param {string} name - The name of the command.
  764. * @returns {void}
  765. */
  766. executeCommand(name, ...args) {
  767. if (!(name in commands)) {
  768. console.error('Not supported command name.');
  769. return;
  770. }
  771. this._transport.sendEvent({
  772. data: args,
  773. name: commands[name]
  774. });
  775. }
  776. /**
  777. * Executes commands. The available commands are:
  778. * {@code displayName} - Sets the display name of the local participant to
  779. * the value passed in the arguments array.
  780. * {@code toggleAudio} - Mutes / unmutes audio. No arguments.
  781. * {@code toggleVideo} - Mutes / unmutes video. No arguments.
  782. * {@code toggleFilmStrip} - Hides / shows the filmstrip. No arguments.
  783. * {@code toggleChat} - Hides / shows chat. No arguments.
  784. * {@code toggleShareScreen} - Starts / stops screen sharing. No arguments.
  785. *
  786. * @param {Object} commandList - The object with commands to be executed.
  787. * The keys of the object are the commands that will be executed and the
  788. * values are the arguments for the command.
  789. * @returns {void}
  790. */
  791. executeCommands(commandList) {
  792. for (const key in commandList) { // eslint-disable-line guard-for-in
  793. this.executeCommand(key, commandList[key]);
  794. }
  795. }
  796. /**
  797. * Returns Promise that resolves with a list of available devices.
  798. *
  799. * @returns {Promise}
  800. */
  801. getAvailableDevices() {
  802. return getAvailableDevices(this._transport);
  803. }
  804. /**
  805. * Gets a list of the currently sharing participant id's.
  806. *
  807. * @returns {Promise} - Resolves with the list of participant id's currently sharing.
  808. */
  809. getContentSharingParticipants() {
  810. return this._transport.sendRequest({
  811. name: 'get-content-sharing-participants'
  812. });
  813. }
  814. /**
  815. * Returns Promise that resolves with current selected devices.
  816. *
  817. * @returns {Promise}
  818. */
  819. getCurrentDevices() {
  820. return getCurrentDevices(this._transport);
  821. }
  822. /**
  823. * Returns any custom avatars backgrounds.
  824. *
  825. * @returns {Promise} - Resolves with the list of custom avatar backgrounds.
  826. */
  827. getCustomAvatarBackgrounds() {
  828. return this._transport.sendRequest({
  829. name: 'get-custom-avatar-backgrounds'
  830. });
  831. }
  832. /**
  833. * Returns the current livestream url.
  834. *
  835. * @returns {Promise} - Resolves with the current livestream URL if exists, with
  836. * undefined if not and rejects on failure.
  837. */
  838. getLivestreamUrl() {
  839. return this._transport.sendRequest({
  840. name: 'get-livestream-url'
  841. });
  842. }
  843. /**
  844. * Returns the conference participants information.
  845. *
  846. * @returns {Array<Object>} - Returns an array containing participants
  847. * information like participant id, display name, avatar URL and email.
  848. */
  849. getParticipantsInfo() {
  850. const participantIds = Object.keys(this._participants);
  851. const participantsInfo = Object.values(this._participants);
  852. participantsInfo.forEach((participant, idx) => {
  853. participant.participantId = participantIds[idx];
  854. });
  855. return participantsInfo;
  856. }
  857. /**
  858. * Returns the current video quality setting.
  859. *
  860. * @returns {number}
  861. */
  862. getVideoQuality() {
  863. return this._videoQuality;
  864. }
  865. /**
  866. * Check if the audio is available.
  867. *
  868. * @returns {Promise} - Resolves with true if the audio available, with
  869. * false if not and rejects on failure.
  870. */
  871. isAudioAvailable() {
  872. return this._transport.sendRequest({
  873. name: 'is-audio-available'
  874. });
  875. }
  876. /**
  877. * Returns Promise that resolves with true if the device change is available
  878. * and with false if not.
  879. *
  880. * @param {string} [deviceType] - Values - 'output', 'input' or undefined.
  881. * Default - 'input'.
  882. * @returns {Promise}
  883. */
  884. isDeviceChangeAvailable(deviceType) {
  885. return isDeviceChangeAvailable(this._transport, deviceType);
  886. }
  887. /**
  888. * Returns Promise that resolves with true if the device list is available
  889. * and with false if not.
  890. *
  891. * @returns {Promise}
  892. */
  893. isDeviceListAvailable() {
  894. return isDeviceListAvailable(this._transport);
  895. }
  896. /**
  897. * Returns Promise that resolves with true if multiple audio input is supported
  898. * and with false if not.
  899. *
  900. * @returns {Promise}
  901. */
  902. isMultipleAudioInputSupported() {
  903. return isMultipleAudioInputSupported(this._transport);
  904. }
  905. /**
  906. * Invite people to the call.
  907. *
  908. * @param {Array<Object>} invitees - The invitees.
  909. * @returns {Promise} - Resolves on success and rejects on failure.
  910. */
  911. invite(invitees) {
  912. if (!Array.isArray(invitees) || invitees.length === 0) {
  913. return Promise.reject(new TypeError('Invalid Argument'));
  914. }
  915. return this._transport.sendRequest({
  916. name: 'invite',
  917. invitees
  918. });
  919. }
  920. /**
  921. * Returns the audio mute status.
  922. *
  923. * @returns {Promise} - Resolves with the audio mute status and rejects on
  924. * failure.
  925. */
  926. isAudioMuted() {
  927. return this._transport.sendRequest({
  928. name: 'is-audio-muted'
  929. });
  930. }
  931. /**
  932. * Returns the audio disabled status.
  933. *
  934. * @returns {Promise} - Resolves with the audio disabled status and rejects on
  935. * failure.
  936. */
  937. isAudioDisabled() {
  938. return this._transport.sendRequest({
  939. name: 'is-audio-disabled'
  940. });
  941. }
  942. /**
  943. * Returns the moderation on status on the given mediaType.
  944. *
  945. * @param {string} mediaType - The media type for which to check moderation.
  946. * @returns {Promise} - Resolves with the moderation on status and rejects on
  947. * failure.
  948. */
  949. isModerationOn(mediaType) {
  950. return this._transport.sendRequest({
  951. name: 'is-moderation-on',
  952. mediaType
  953. });
  954. }
  955. /**
  956. * Returns force muted status of the given participant id for the given media type.
  957. *
  958. * @param {string} participantId - The id of the participant to check.
  959. * @param {string} mediaType - The media type for which to check.
  960. * @returns {Promise} - Resolves with the force muted status and rejects on
  961. * failure.
  962. */
  963. isParticipantForceMuted(participantId, mediaType) {
  964. return this._transport.sendRequest({
  965. name: 'is-participant-force-muted',
  966. participantId,
  967. mediaType
  968. });
  969. }
  970. /**
  971. * Returns whether the participants pane is open.
  972. *
  973. * @returns {Promise} - Resolves with true if the participants pane is open
  974. * and with false if not.
  975. */
  976. isParticipantsPaneOpen() {
  977. return this._transport.sendRequest({
  978. name: 'is-participants-pane-open'
  979. });
  980. }
  981. /**
  982. * Returns screen sharing status.
  983. *
  984. * @returns {Promise} - Resolves with screensharing status and rejects on failure.
  985. */
  986. isSharingScreen() {
  987. return this._transport.sendRequest({
  988. name: 'is-sharing-screen'
  989. });
  990. }
  991. /**
  992. * Returns whether meeting is started silent.
  993. *
  994. * @returns {Promise} - Resolves with start silent status.
  995. */
  996. isStartSilent() {
  997. return this._transport.sendRequest({
  998. name: 'is-start-silent'
  999. });
  1000. }
  1001. /**
  1002. * Returns the avatar URL of a participant.
  1003. *
  1004. * @param {string} participantId - The id of the participant.
  1005. * @returns {string} The avatar URL.
  1006. */
  1007. getAvatarURL(participantId) {
  1008. const { avatarURL } = this._participants[participantId] || {};
  1009. return avatarURL;
  1010. }
  1011. /**
  1012. * Gets the deployment info.
  1013. *
  1014. * @returns {Promise} - Resolves with the deployment info object.
  1015. */
  1016. getDeploymentInfo() {
  1017. return this._transport.sendRequest({
  1018. name: 'deployment-info'
  1019. });
  1020. }
  1021. /**
  1022. * Returns the display name of a participant.
  1023. *
  1024. * @param {string} participantId - The id of the participant.
  1025. * @returns {string} The display name.
  1026. */
  1027. getDisplayName(participantId) {
  1028. const { displayName } = this._participants[participantId] || {};
  1029. return displayName;
  1030. }
  1031. /**
  1032. * Returns the email of a participant.
  1033. *
  1034. * @param {string} participantId - The id of the participant.
  1035. * @returns {string} The email.
  1036. */
  1037. getEmail(participantId) {
  1038. const { email } = this._participants[participantId] || {};
  1039. return email;
  1040. }
  1041. /**
  1042. * Returns the iframe that loads Jitsi Meet.
  1043. *
  1044. * @returns {HTMLElement} The iframe.
  1045. */
  1046. getIFrame() {
  1047. return this._frame;
  1048. }
  1049. /**
  1050. * Returns the number of participants in the conference from all rooms. The local
  1051. * participant is included.
  1052. *
  1053. * @returns {int} The number of participants in the conference.
  1054. */
  1055. getNumberOfParticipants() {
  1056. return this._numberOfParticipants;
  1057. }
  1058. /**
  1059. * Check if the video is available.
  1060. *
  1061. * @returns {Promise} - Resolves with true if the video available, with
  1062. * false if not and rejects on failure.
  1063. */
  1064. isVideoAvailable() {
  1065. return this._transport.sendRequest({
  1066. name: 'is-video-available'
  1067. });
  1068. }
  1069. /**
  1070. * Returns the audio mute status.
  1071. *
  1072. * @returns {Promise} - Resolves with the audio mute status and rejects on
  1073. * failure.
  1074. */
  1075. isVideoMuted() {
  1076. return this._transport.sendRequest({
  1077. name: 'is-video-muted'
  1078. });
  1079. }
  1080. /**
  1081. * Returns the list of breakout rooms.
  1082. *
  1083. * @returns {Promise} Resolves with the list of breakout rooms.
  1084. */
  1085. listBreakoutRooms() {
  1086. return this._transport.sendRequest({
  1087. name: 'list-breakout-rooms'
  1088. });
  1089. }
  1090. /**
  1091. * Pins a participant's video on to the stage view.
  1092. *
  1093. * @param {string} participantId - Participant id (JID) of the participant
  1094. * that needs to be pinned on the stage view.
  1095. * @param {string} [videoType] - Indicates the type of thumbnail to be pinned when multistream support is enabled.
  1096. * Accepts "camera" or "desktop" values. Default is "camera". Any invalid values will be ignored and default will
  1097. * be used.
  1098. * @returns {void}
  1099. */
  1100. pinParticipant(participantId, videoType) {
  1101. this.executeCommand('pinParticipant', participantId, videoType);
  1102. }
  1103. /**
  1104. * Removes event listener.
  1105. *
  1106. * @param {string} event - The name of the event.
  1107. * @returns {void}
  1108. *
  1109. * @deprecated
  1110. * NOTE: This method is not removed for backward comatability purposes.
  1111. */
  1112. removeEventListener(event) {
  1113. this.removeAllListeners(event);
  1114. }
  1115. /**
  1116. * Removes event listeners.
  1117. *
  1118. * @param {Array<string>} eventList - Array with the names of the events.
  1119. * @returns {void}
  1120. *
  1121. * @deprecated
  1122. * NOTE: This method is not removed for backward comatability purposes.
  1123. */
  1124. removeEventListeners(eventList) {
  1125. eventList.forEach(event => this.removeEventListener(event));
  1126. }
  1127. /**
  1128. * Resizes the large video container as per the dimensions provided.
  1129. *
  1130. * @param {number} width - Width that needs to be applied on the large video container.
  1131. * @param {number} height - Height that needs to be applied on the large video container.
  1132. * @returns {void}
  1133. */
  1134. resizeLargeVideo(width, height) {
  1135. if (width <= this._width && height <= this._height) {
  1136. this.executeCommand('resizeLargeVideo', width, height);
  1137. }
  1138. }
  1139. /**
  1140. * Passes an event along to the local conference participant to establish
  1141. * or update a direct peer connection. This is currently used for developing
  1142. * wireless screensharing with room integration and it is advised against to
  1143. * use as its api may change.
  1144. *
  1145. * @param {Object} event - An object with information to pass along.
  1146. * @param {Object} event.data - The payload of the event.
  1147. * @param {string} event.from - The jid of the sender of the event. Needed
  1148. * when a reply is to be sent regarding the event.
  1149. * @returns {void}
  1150. */
  1151. sendProxyConnectionEvent(event) {
  1152. this._transport.sendEvent({
  1153. data: [ event ],
  1154. name: 'proxy-connection-event'
  1155. });
  1156. }
  1157. /**
  1158. * Sets the audio input device to the one with the label or id that is
  1159. * passed.
  1160. *
  1161. * @param {string} label - The label of the new device.
  1162. * @param {string} deviceId - The id of the new device.
  1163. * @returns {Promise}
  1164. */
  1165. setAudioInputDevice(label, deviceId) {
  1166. return setAudioInputDevice(this._transport, label, deviceId);
  1167. }
  1168. /**
  1169. * Sets the audio output device to the one with the label or id that is
  1170. * passed.
  1171. *
  1172. * @param {string} label - The label of the new device.
  1173. * @param {string} deviceId - The id of the new device.
  1174. * @returns {Promise}
  1175. */
  1176. setAudioOutputDevice(label, deviceId) {
  1177. return setAudioOutputDevice(this._transport, label, deviceId);
  1178. }
  1179. /**
  1180. * Displays the given participant on the large video. If no participant id is specified,
  1181. * dominant and pinned speakers will be taken into consideration while selecting the
  1182. * the large video participant.
  1183. *
  1184. * @param {string} participantId - Jid of the participant to be displayed on the large video.
  1185. * @param {string} [videoType] - Indicates the type of video to be set when multistream support is enabled.
  1186. * Accepts "camera" or "desktop" values. Default is "camera". Any invalid values will be ignored and default will
  1187. * be used.
  1188. * @returns {void}
  1189. */
  1190. setLargeVideoParticipant(participantId, videoType) {
  1191. this.executeCommand('setLargeVideoParticipant', participantId, videoType);
  1192. }
  1193. /**
  1194. * Sets the video input device to the one with the label or id that is
  1195. * passed.
  1196. *
  1197. * @param {string} label - The label of the new device.
  1198. * @param {string} deviceId - The id of the new device.
  1199. * @returns {Promise}
  1200. */
  1201. setVideoInputDevice(label, deviceId) {
  1202. return setVideoInputDevice(this._transport, label, deviceId);
  1203. }
  1204. /**
  1205. * Starts a file recording or streaming session depending on the passed on params.
  1206. * For RTMP streams, `rtmpStreamKey` must be passed on. `rtmpBroadcastID` is optional.
  1207. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  1208. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  1209. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  1210. * No other params should be passed.
  1211. *
  1212. * @param {Object} options - An object with config options to pass along.
  1213. * @param { string } options.mode - Recording mode, either `file` or `stream`.
  1214. * @param { string } options.dropboxToken - Dropbox oauth2 token.
  1215. * @param { boolean } options.shouldShare - Whether the recording should be shared with the participants or not.
  1216. * Only applies to certain jitsi meet deploys.
  1217. * @param { string } options.rtmpStreamKey - The RTMP stream key.
  1218. * @param { string } options.rtmpBroadcastID - The RTMP broadcast ID.
  1219. * @param { string } options.youtubeStreamKey - The youtube stream key.
  1220. * @param { string } options.youtubeBroadcastID - The youtube broadcast ID.
  1221. * @returns {void}
  1222. */
  1223. startRecording(options) {
  1224. this.executeCommand('startRecording', options);
  1225. }
  1226. /**
  1227. * Stops a recording or streaming session that is in progress.
  1228. *
  1229. * @param {string} mode - `file` or `stream`.
  1230. * @returns {void}
  1231. */
  1232. stopRecording(mode) {
  1233. this.executeCommand('stopRecording', mode);
  1234. }
  1235. /**
  1236. * Sets e2ee enabled/disabled.
  1237. *
  1238. * @param {boolean} enabled - The new value for e2ee enabled.
  1239. * @returns {void}
  1240. */
  1241. toggleE2EE(enabled) {
  1242. this.executeCommand('toggleE2EE', enabled);
  1243. }
  1244. /**
  1245. * Sets the key and keyIndex for e2ee.
  1246. *
  1247. * @param {Object} keyInfo - Json containing key information.
  1248. * @param {CryptoKey} [keyInfo.encryptionKey] - The encryption key.
  1249. * @param {number} [keyInfo.index] - The index of the encryption key.
  1250. * @returns {void}
  1251. */
  1252. async setMediaEncryptionKey(keyInfo) {
  1253. const { key, index } = keyInfo;
  1254. if (key) {
  1255. const exportedKey = await crypto.subtle.exportKey('raw', key);
  1256. this.executeCommand('setMediaEncryptionKey', JSON.stringify({
  1257. exportedKey: Array.from(new Uint8Array(exportedKey)),
  1258. index }));
  1259. } else {
  1260. this.executeCommand('setMediaEncryptionKey', JSON.stringify({
  1261. exportedKey: false,
  1262. index }));
  1263. }
  1264. }
  1265. }