Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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