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.

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