Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

external_api.js 48KB

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