Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

external_api.js 46KB

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