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

external_api.js 47KB

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