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

external_api.js 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. import EventEmitter from 'events';
  2. import { urlObjectToString } from '../../../react/features/base/util/uri';
  3. import {
  4. PostMessageTransportBackend,
  5. Transport
  6. } from '../../transport';
  7. import electronPopupsConfig from './electronPopupsConfig.json';
  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. avatarUrl: 'avatar-url',
  27. displayName: 'display-name',
  28. e2eeKey: 'e2ee-key',
  29. email: 'email',
  30. toggleLobby: 'toggle-lobby',
  31. hangup: 'video-hangup',
  32. muteEveryone: 'mute-everyone',
  33. password: 'password',
  34. sendEndpointTextMessage: 'send-endpoint-text-message',
  35. sendTones: 'send-tones',
  36. setVideoQuality: 'set-video-quality',
  37. startRecording: 'start-recording',
  38. stopRecording: 'stop-recording',
  39. subject: 'subject',
  40. submitFeedback: 'submit-feedback',
  41. toggleAudio: 'toggle-audio',
  42. toggleChat: 'toggle-chat',
  43. toggleFilmStrip: 'toggle-film-strip',
  44. toggleShareScreen: 'toggle-share-screen',
  45. toggleTileView: 'toggle-tile-view',
  46. toggleVideo: 'toggle-video'
  47. };
  48. /**
  49. * Maps the names of the events expected by the API with the name of the
  50. * events expected by jitsi-meet
  51. */
  52. const events = {
  53. 'avatar-changed': 'avatarChanged',
  54. 'audio-availability-changed': 'audioAvailabilityChanged',
  55. 'audio-mute-status-changed': 'audioMuteStatusChanged',
  56. 'camera-error': 'cameraError',
  57. 'device-list-changed': 'deviceListChanged',
  58. 'display-name-change': 'displayNameChange',
  59. 'email-change': 'emailChange',
  60. 'endpoint-text-message-received': 'endpointTextMessageReceived',
  61. 'feedback-submitted': 'feedbackSubmitted',
  62. 'feedback-prompt-displayed': 'feedbackPromptDisplayed',
  63. 'filmstrip-display-changed': 'filmstripDisplayChanged',
  64. 'incoming-message': 'incomingMessage',
  65. 'mic-error': 'micError',
  66. 'outgoing-message': 'outgoingMessage',
  67. 'participant-joined': 'participantJoined',
  68. 'participant-kicked-out': 'participantKickedOut',
  69. 'participant-left': 'participantLeft',
  70. 'participant-role-changed': 'participantRoleChanged',
  71. 'password-required': 'passwordRequired',
  72. 'proxy-connection-event': 'proxyConnectionEvent',
  73. 'video-ready-to-close': 'readyToClose',
  74. 'video-conference-joined': 'videoConferenceJoined',
  75. 'video-conference-left': 'videoConferenceLeft',
  76. 'video-availability-changed': 'videoAvailabilityChanged',
  77. 'video-mute-status-changed': 'videoMuteStatusChanged',
  78. 'screen-sharing-status-changed': 'screenSharingStatusChanged',
  79. 'dominant-speaker-changed': 'dominantSpeakerChanged',
  80. 'subject-change': 'subjectChange',
  81. 'suspend-detected': 'suspendDetected',
  82. 'tile-view-changed': 'tileViewChanged'
  83. };
  84. /**
  85. * Last id of api object
  86. * @type {number}
  87. */
  88. let id = 0;
  89. /**
  90. * Adds given number to the numberOfParticipants property of given APIInstance.
  91. *
  92. * @param {JitsiMeetExternalAPI} APIInstance - The instance of the API.
  93. * @param {int} number - The number of participants to be added to
  94. * numberOfParticipants property (this parameter can be negative number if the
  95. * numberOfParticipants should be decreased).
  96. * @returns {void}
  97. */
  98. function changeParticipantNumber(APIInstance, number) {
  99. APIInstance._numberOfParticipants += number;
  100. }
  101. /**
  102. * Generates the URL for the iframe.
  103. *
  104. * @param {string} domain - The domain name of the server that hosts the
  105. * conference.
  106. * @param {string} [options] - Another optional parameters.
  107. * @param {Object} [options.configOverwrite] - Object containing configuration
  108. * options defined in config.js to be overridden.
  109. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  110. * configuration options defined in interface_config.js to be overridden.
  111. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  112. * authentication.
  113. * @param {boolean} [options.noSSL] - If the value is true https won't be used.
  114. * @param {string} [options.roomName] - The name of the room to join.
  115. * @returns {string} The URL.
  116. */
  117. function generateURL(domain, options = {}) {
  118. return urlObjectToString({
  119. ...options,
  120. url:
  121. `${options.noSSL ? 'http' : 'https'}://${
  122. domain}/#jitsi_meet_external_api_id=${id}`
  123. });
  124. }
  125. /**
  126. * Parses the arguments passed to the constructor. If the old format is used
  127. * the function translates the arguments to the new format.
  128. *
  129. * @param {Array} args - The arguments to be parsed.
  130. * @returns {Object} JS object with properties.
  131. */
  132. function parseArguments(args) {
  133. if (!args.length) {
  134. return {};
  135. }
  136. const firstArg = args[0];
  137. switch (typeof firstArg) {
  138. case 'string': // old arguments format
  139. case undefined: {
  140. // Not sure which format but we are trying to parse the old
  141. // format because if the new format is used everything will be undefined
  142. // anyway.
  143. const [
  144. roomName,
  145. width,
  146. height,
  147. parentNode,
  148. configOverwrite,
  149. interfaceConfigOverwrite,
  150. noSSL,
  151. jwt,
  152. onload
  153. ] = args;
  154. return {
  155. roomName,
  156. width,
  157. height,
  158. parentNode,
  159. configOverwrite,
  160. interfaceConfigOverwrite,
  161. noSSL,
  162. jwt,
  163. onload
  164. };
  165. }
  166. case 'object': // new arguments format
  167. return args[0];
  168. default:
  169. throw new Error('Can\'t parse the arguments!');
  170. }
  171. }
  172. /**
  173. * Compute valid values for height and width. If a number is specified it's
  174. * treated as pixel units. If the value is expressed in px, em, pt or
  175. * percentage, it's used as is.
  176. *
  177. * @param {any} value - The value to be parsed.
  178. * @returns {string|undefined} The parsed value that can be used for setting
  179. * sizes through the style property. If invalid value is passed the method
  180. * retuns undefined.
  181. */
  182. function parseSizeParam(value) {
  183. let parsedValue;
  184. // This regex parses values of the form 100px, 100em, 100pt or 100%.
  185. // Values like 100 or 100px are handled outside of the regex, and
  186. // invalid values will be ignored and the minimum will be used.
  187. const re = /([0-9]*\.?[0-9]+)(em|pt|px|%)$/;
  188. if (typeof value === 'string' && String(value).match(re) !== null) {
  189. parsedValue = value;
  190. } else if (typeof value === 'number') {
  191. parsedValue = `${value}px`;
  192. }
  193. return parsedValue;
  194. }
  195. /**
  196. * The IFrame API interface class.
  197. */
  198. export default class JitsiMeetExternalAPI extends EventEmitter {
  199. /**
  200. * Constructs new API instance. Creates iframe and loads Jitsi Meet in it.
  201. *
  202. * @param {string} domain - The domain name of the server that hosts the
  203. * conference.
  204. * @param {Object} [options] - Optional arguments.
  205. * @param {string} [options.roomName] - The name of the room to join.
  206. * @param {number|string} [options.width] - Width of the iframe. Check
  207. * parseSizeParam for format details.
  208. * @param {number|string} [options.height] - Height of the iframe. Check
  209. * parseSizeParam for format details.
  210. * @param {DOMElement} [options.parentNode] - The node that will contain the
  211. * iframe.
  212. * @param {Object} [options.configOverwrite] - Object containing
  213. * configuration options defined in config.js to be overridden.
  214. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  215. * configuration options defined in interface_config.js to be overridden.
  216. * @param {boolean} [options.noSSL] - If the value is true https won't be
  217. * used.
  218. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  219. * authentication.
  220. * @param {string} [options.onload] - The onload function that will listen
  221. * for iframe onload event.
  222. * @param {Array<Object>} [options.invitees] - Array of objects containing
  223. * information about new participants that will be invited in the call.
  224. * @param {Array<Object>} [options.devices] - Array of objects containing
  225. * information about the initial devices that will be used in the call.
  226. * @param {Object} [options.userInfo] - Object containing information about
  227. * the participant opening the meeting.
  228. * @param {string} [options.e2eeKey] - The key used for End-to-End encryption.
  229. * THIS IS EXPERIMENTAL.
  230. */
  231. constructor(domain, ...args) {
  232. super();
  233. const {
  234. roomName = '',
  235. width = '100%',
  236. height = '100%',
  237. parentNode = document.body,
  238. configOverwrite = {},
  239. interfaceConfigOverwrite = {},
  240. noSSL = false,
  241. jwt = undefined,
  242. onload = undefined,
  243. invitees,
  244. devices,
  245. userInfo,
  246. e2eeKey
  247. } = parseArguments(args);
  248. this._parentNode = parentNode;
  249. this._url = generateURL(domain, {
  250. configOverwrite,
  251. interfaceConfigOverwrite,
  252. jwt,
  253. noSSL,
  254. roomName,
  255. devices,
  256. userInfo
  257. });
  258. this._createIFrame(height, width, onload);
  259. this._transport = new Transport({
  260. backend: new PostMessageTransportBackend({
  261. postisOptions: {
  262. allowedOrigin: new URL(this._url).origin,
  263. scope: `jitsi_meet_external_api_${id}`,
  264. window: this._frame.contentWindow
  265. }
  266. })
  267. });
  268. if (Array.isArray(invitees) && invitees.length > 0) {
  269. this.invite(invitees);
  270. }
  271. this._tmpE2EEKey = e2eeKey;
  272. this._isLargeVideoVisible = true;
  273. this._numberOfParticipants = 0;
  274. this._participants = {};
  275. this._myUserID = undefined;
  276. this._onStageParticipant = undefined;
  277. this._setupListeners();
  278. id++;
  279. }
  280. /**
  281. * Creates the iframe element.
  282. *
  283. * @param {number|string} height - The height of the iframe. Check
  284. * parseSizeParam for format details.
  285. * @param {number|string} width - The with of the iframe. Check
  286. * parseSizeParam for format details.
  287. * @param {Function} onload - The function that will listen
  288. * for onload event.
  289. * @returns {void}
  290. *
  291. * @private
  292. */
  293. _createIFrame(height, width, onload) {
  294. const frameName = `jitsiConferenceFrame${id}`;
  295. this._frame = document.createElement('iframe');
  296. this._frame.allow = 'camera; microphone; display-capture';
  297. this._frame.src = this._url;
  298. this._frame.name = frameName;
  299. this._frame.id = frameName;
  300. this._setSize(height, width);
  301. this._frame.setAttribute('allowFullScreen', 'true');
  302. this._frame.style.border = 0;
  303. if (onload) {
  304. // waits for iframe resources to load
  305. // and fires event when it is done
  306. this._frame.onload = onload;
  307. }
  308. this._frame = this._parentNode.appendChild(this._frame);
  309. }
  310. /**
  311. * Returns arrays with the all resources for the always on top feature.
  312. *
  313. * @returns {Array<string>}
  314. */
  315. _getAlwaysOnTopResources() {
  316. const iframeWindow = this._frame.contentWindow;
  317. const iframeDocument = iframeWindow.document;
  318. let baseURL = '';
  319. const base = iframeDocument.querySelector('base');
  320. if (base && base.href) {
  321. baseURL = base.href;
  322. } else {
  323. const { protocol, host } = iframeWindow.location;
  324. baseURL = `${protocol}//${host}`;
  325. }
  326. return ALWAYS_ON_TOP_FILENAMES.map(
  327. filename => (new URL(filename, baseURL)).href
  328. );
  329. }
  330. /**
  331. * Returns the id of the on stage participant.
  332. *
  333. * @returns {string} - The id of the on stage participant.
  334. */
  335. _getOnStageParticipant() {
  336. return this._onStageParticipant;
  337. }
  338. /**
  339. * Getter for the large video element in Jitsi Meet.
  340. *
  341. * @returns {HTMLElement|undefined} - The large video.
  342. */
  343. _getLargeVideo() {
  344. const iframe = this.getIFrame();
  345. if (!this._isLargeVideoVisible
  346. || !iframe
  347. || !iframe.contentWindow
  348. || !iframe.contentWindow.document) {
  349. return;
  350. }
  351. return iframe.contentWindow.document.getElementById('largeVideo');
  352. }
  353. /**
  354. * Getter for participant specific video element in Jitsi Meet.
  355. *
  356. * @param {string|undefined} participantId - Id of participant to return the video for.
  357. *
  358. * @returns {HTMLElement|undefined} - The requested video. Will return the local video
  359. * by default if participantId is undefined.
  360. */
  361. _getParticipantVideo(participantId) {
  362. const iframe = this.getIFrame();
  363. if (!iframe
  364. || !iframe.contentWindow
  365. || !iframe.contentWindow.document) {
  366. return;
  367. }
  368. if (typeof participantId === 'undefined' || participantId === this._myUserID) {
  369. return iframe.contentWindow.document.getElementById('localVideo_container');
  370. }
  371. return iframe.contentWindow.document.querySelector(`#participant_${participantId} video`);
  372. }
  373. /**
  374. * Sets the size of the iframe element.
  375. *
  376. * @param {number|string} height - The height of the iframe.
  377. * @param {number|string} width - The with of the iframe.
  378. * @returns {void}
  379. *
  380. * @private
  381. */
  382. _setSize(height, width) {
  383. const parsedHeight = parseSizeParam(height);
  384. const parsedWidth = parseSizeParam(width);
  385. if (parsedHeight !== undefined) {
  386. this._frame.style.height = parsedHeight;
  387. }
  388. if (parsedWidth !== undefined) {
  389. this._frame.style.width = parsedWidth;
  390. }
  391. }
  392. /**
  393. * Setups listeners that are used internally for JitsiMeetExternalAPI.
  394. *
  395. * @returns {void}
  396. *
  397. * @private
  398. */
  399. _setupListeners() {
  400. this._transport.on('event', ({ name, ...data }) => {
  401. const userID = data.id;
  402. switch (name) {
  403. case 'video-conference-joined': {
  404. if (typeof this._tmpE2EEKey !== 'undefined') {
  405. this.executeCommand(commands.e2eeKey, this._tmpE2EEKey);
  406. this._tmpE2EEKey = undefined;
  407. }
  408. this._myUserID = userID;
  409. this._participants[userID] = {
  410. avatarURL: data.avatarURL
  411. };
  412. }
  413. // eslint-disable-next-line no-fallthrough
  414. case 'participant-joined': {
  415. this._participants[userID] = this._participants[userID] || {};
  416. this._participants[userID].displayName = data.displayName;
  417. this._participants[userID].formattedDisplayName
  418. = data.formattedDisplayName;
  419. changeParticipantNumber(this, 1);
  420. break;
  421. }
  422. case 'participant-left':
  423. changeParticipantNumber(this, -1);
  424. delete this._participants[userID];
  425. break;
  426. case 'display-name-change': {
  427. const user = this._participants[userID];
  428. if (user) {
  429. user.displayName = data.displayname;
  430. user.formattedDisplayName = data.formattedDisplayName;
  431. }
  432. break;
  433. }
  434. case 'email-change': {
  435. const user = this._participants[userID];
  436. if (user) {
  437. user.email = data.email;
  438. }
  439. break;
  440. }
  441. case 'avatar-changed': {
  442. const user = this._participants[userID];
  443. if (user) {
  444. user.avatarURL = data.avatarURL;
  445. }
  446. break;
  447. }
  448. case 'on-stage-participant-changed':
  449. this._onStageParticipant = userID;
  450. this.emit('largeVideoChanged');
  451. break;
  452. case 'large-video-visibility-changed':
  453. this._isLargeVideoVisible = data.isVisible;
  454. this.emit('largeVideoChanged');
  455. break;
  456. case 'video-conference-left':
  457. changeParticipantNumber(this, -1);
  458. delete this._participants[this._myUserID];
  459. break;
  460. }
  461. const eventName = events[name];
  462. if (eventName) {
  463. this.emit(eventName, data);
  464. return true;
  465. }
  466. return false;
  467. });
  468. }
  469. /**
  470. * Adds event listener to Meet Jitsi.
  471. *
  472. * @param {string} event - The name of the event.
  473. * @param {Function} listener - The listener.
  474. * @returns {void}
  475. *
  476. * @deprecated
  477. * NOTE: This method is not removed for backward comatability purposes.
  478. */
  479. addEventListener(event, listener) {
  480. this.on(event, listener);
  481. }
  482. /**
  483. * Adds event listeners to Meet Jitsi.
  484. *
  485. * @param {Object} listeners - The object key should be the name of
  486. * the event and value - the listener.
  487. * Currently we support the following
  488. * events:
  489. * {@code incomingMessage} - receives event notifications about incoming
  490. * messages. The listener will receive object with the following structure:
  491. * {{
  492. * 'from': from,//JID of the user that sent the message
  493. * 'nick': nick,//the nickname of the user that sent the message
  494. * 'message': txt//the text of the message
  495. * }}
  496. * {@code outgoingMessage} - receives event notifications about outgoing
  497. * messages. The listener will receive object with the following structure:
  498. * {{
  499. * 'message': txt//the text of the message
  500. * }}
  501. * {@code displayNameChanged} - receives event notifications about display
  502. * name change. The listener will receive object with the following
  503. * structure:
  504. * {{
  505. * jid: jid,//the JID of the participant that changed his display name
  506. * displayname: displayName //the new display name
  507. * }}
  508. * {@code participantJoined} - receives event notifications about new
  509. * participant.
  510. * The listener will receive object with the following structure:
  511. * {{
  512. * jid: jid //the jid of the participant
  513. * }}
  514. * {@code participantLeft} - receives event notifications about the
  515. * participant that left the room.
  516. * The listener will receive object with the following structure:
  517. * {{
  518. * jid: jid //the jid of the participant
  519. * }}
  520. * {@code videoConferenceJoined} - receives event notifications about the
  521. * local user has successfully joined the video conference.
  522. * The listener will receive object with the following structure:
  523. * {{
  524. * roomName: room //the room name of the conference
  525. * }}
  526. * {@code videoConferenceLeft} - receives event notifications about the
  527. * local user has left the video conference.
  528. * The listener will receive object with the following structure:
  529. * {{
  530. * roomName: room //the room name of the conference
  531. * }}
  532. * {@code screenSharingStatusChanged} - receives event notifications about
  533. * turning on/off the local user screen sharing.
  534. * The listener will receive object with the following structure:
  535. * {{
  536. * on: on //whether screen sharing is on
  537. * }}
  538. * {@code dominantSpeakerChanged} - receives event notifications about
  539. * change in the dominant speaker.
  540. * The listener will receive object with the following structure:
  541. * {{
  542. * id: participantId //participantId of the new dominant speaker
  543. * }}
  544. * {@code suspendDetected} - receives event notifications about detecting suspend event in host computer.
  545. * {@code readyToClose} - all hangup operations are completed and Jitsi Meet
  546. * is ready to be disposed.
  547. * @returns {void}
  548. *
  549. * @deprecated
  550. * NOTE: This method is not removed for backward comatability purposes.
  551. */
  552. addEventListeners(listeners) {
  553. for (const event in listeners) { // eslint-disable-line guard-for-in
  554. this.addEventListener(event, listeners[event]);
  555. }
  556. }
  557. /**
  558. * Removes the listeners and removes the Jitsi Meet frame.
  559. *
  560. * @returns {void}
  561. */
  562. dispose() {
  563. this.emit('_willDispose');
  564. this._transport.dispose();
  565. this.removeAllListeners();
  566. if (this._frame && this._frame.parentNode) {
  567. this._frame.parentNode.removeChild(this._frame);
  568. }
  569. }
  570. /**
  571. * Executes command. The available commands are:
  572. * {@code displayName} - Sets the display name of the local participant to
  573. * the value passed in the arguments array.
  574. * {@code subject} - Sets the subject of the conference, the value passed
  575. * in the arguments array. Note: Available only for moderator.
  576. *
  577. * {@code toggleAudio} - Mutes / unmutes audio with no arguments.
  578. * {@code toggleVideo} - Mutes / unmutes video with no arguments.
  579. * {@code toggleFilmStrip} - Hides / shows the filmstrip with no arguments.
  580. *
  581. * If the command doesn't require any arguments the parameter should be set
  582. * to empty array or it may be omitted.
  583. *
  584. * @param {string} name - The name of the command.
  585. * @returns {void}
  586. */
  587. executeCommand(name, ...args) {
  588. if (!(name in commands)) {
  589. console.error('Not supported command name.');
  590. return;
  591. }
  592. this._transport.sendEvent({
  593. data: args,
  594. name: commands[name]
  595. });
  596. }
  597. /**
  598. * Executes commands. The available commands are:
  599. * {@code displayName} - Sets the display name of the local participant to
  600. * the value passed in the arguments array.
  601. * {@code toggleAudio} - Mutes / unmutes audio. No arguments.
  602. * {@code toggleVideo} - Mutes / unmutes video. No arguments.
  603. * {@code toggleFilmStrip} - Hides / shows the filmstrip. No arguments.
  604. * {@code toggleChat} - Hides / shows chat. No arguments.
  605. * {@code toggleShareScreen} - Starts / stops screen sharing. No arguments.
  606. *
  607. * @param {Object} commandList - The object with commands to be executed.
  608. * The keys of the object are the commands that will be executed and the
  609. * values are the arguments for the command.
  610. * @returns {void}
  611. */
  612. executeCommands(commandList) {
  613. for (const key in commandList) { // eslint-disable-line guard-for-in
  614. this.executeCommand(key, commandList[key]);
  615. }
  616. }
  617. /**
  618. * Returns Promise that resolves with a list of available devices.
  619. *
  620. * @returns {Promise}
  621. */
  622. getAvailableDevices() {
  623. return getAvailableDevices(this._transport);
  624. }
  625. /**
  626. * Returns Promise that resolves with current selected devices.
  627. *
  628. * @returns {Promise}
  629. */
  630. getCurrentDevices() {
  631. return getCurrentDevices(this._transport);
  632. }
  633. /**
  634. * Check if the audio is available.
  635. *
  636. * @returns {Promise} - Resolves with true if the audio available, with
  637. * false if not and rejects on failure.
  638. */
  639. isAudioAvailable() {
  640. return this._transport.sendRequest({
  641. name: 'is-audio-available'
  642. });
  643. }
  644. /**
  645. * Returns Promise that resolves with true if the device change is available
  646. * and with false if not.
  647. *
  648. * @param {string} [deviceType] - Values - 'output', 'input' or undefined.
  649. * Default - 'input'.
  650. * @returns {Promise}
  651. */
  652. isDeviceChangeAvailable(deviceType) {
  653. return isDeviceChangeAvailable(this._transport, deviceType);
  654. }
  655. /**
  656. * Returns Promise that resolves with true if the device list is available
  657. * and with false if not.
  658. *
  659. * @returns {Promise}
  660. */
  661. isDeviceListAvailable() {
  662. return isDeviceListAvailable(this._transport);
  663. }
  664. /**
  665. * Returns Promise that resolves with true if multiple audio input is supported
  666. * and with false if not.
  667. *
  668. * @returns {Promise}
  669. */
  670. isMultipleAudioInputSupported() {
  671. return isMultipleAudioInputSupported(this._transport);
  672. }
  673. /**
  674. * Invite people to the call.
  675. *
  676. * @param {Array<Object>} invitees - The invitees.
  677. * @returns {Promise} - Resolves on success and rejects on failure.
  678. */
  679. invite(invitees) {
  680. if (!Array.isArray(invitees) || invitees.length === 0) {
  681. return Promise.reject(new TypeError('Invalid Argument'));
  682. }
  683. return this._transport.sendRequest({
  684. name: 'invite',
  685. invitees
  686. });
  687. }
  688. /**
  689. * Returns the audio mute status.
  690. *
  691. * @returns {Promise} - Resolves with the audio mute status and rejects on
  692. * failure.
  693. */
  694. isAudioMuted() {
  695. return this._transport.sendRequest({
  696. name: 'is-audio-muted'
  697. });
  698. }
  699. /**
  700. * Returns screen sharing status.
  701. *
  702. * @returns {Promise} - Resolves with screensharing status and rejects on failure.
  703. */
  704. isSharingScreen() {
  705. return this._transport.sendRequest({
  706. name: 'is-sharing-screen'
  707. });
  708. }
  709. /**
  710. * Returns the avatar URL of a participant.
  711. *
  712. * @param {string} participantId - The id of the participant.
  713. * @returns {string} The avatar URL.
  714. */
  715. getAvatarURL(participantId) {
  716. const { avatarURL } = this._participants[participantId] || {};
  717. return avatarURL;
  718. }
  719. /**
  720. * Returns the display name of a participant.
  721. *
  722. * @param {string} participantId - The id of the participant.
  723. * @returns {string} The display name.
  724. */
  725. getDisplayName(participantId) {
  726. const { displayName } = this._participants[participantId] || {};
  727. return displayName;
  728. }
  729. /**
  730. * Returns the email of a participant.
  731. *
  732. * @param {string} participantId - The id of the participant.
  733. * @returns {string} The email.
  734. */
  735. getEmail(participantId) {
  736. const { email } = this._participants[participantId] || {};
  737. return email;
  738. }
  739. /**
  740. * Returns the formatted display name of a participant.
  741. *
  742. * @param {string} participantId - The id of the participant.
  743. * @returns {string} The formatted display name.
  744. */
  745. _getFormattedDisplayName(participantId) {
  746. const { formattedDisplayName }
  747. = this._participants[participantId] || {};
  748. return formattedDisplayName;
  749. }
  750. /**
  751. * Returns the iframe that loads Jitsi Meet.
  752. *
  753. * @returns {HTMLElement} The iframe.
  754. */
  755. getIFrame() {
  756. return this._frame;
  757. }
  758. /**
  759. * Returns the number of participants in the conference. The local
  760. * participant is included.
  761. *
  762. * @returns {int} The number of participants in the conference.
  763. */
  764. getNumberOfParticipants() {
  765. return this._numberOfParticipants;
  766. }
  767. /**
  768. * Check if the video is available.
  769. *
  770. * @returns {Promise} - Resolves with true if the video available, with
  771. * false if not and rejects on failure.
  772. */
  773. isVideoAvailable() {
  774. return this._transport.sendRequest({
  775. name: 'is-video-available'
  776. });
  777. }
  778. /**
  779. * Returns the audio mute status.
  780. *
  781. * @returns {Promise} - Resolves with the audio mute status and rejects on
  782. * failure.
  783. */
  784. isVideoMuted() {
  785. return this._transport.sendRequest({
  786. name: 'is-video-muted'
  787. });
  788. }
  789. /**
  790. * Removes event listener.
  791. *
  792. * @param {string} event - The name of the event.
  793. * @returns {void}
  794. *
  795. * @deprecated
  796. * NOTE: This method is not removed for backward comatability purposes.
  797. */
  798. removeEventListener(event) {
  799. this.removeAllListeners(event);
  800. }
  801. /**
  802. * Removes event listeners.
  803. *
  804. * @param {Array<string>} eventList - Array with the names of the events.
  805. * @returns {void}
  806. *
  807. * @deprecated
  808. * NOTE: This method is not removed for backward comatability purposes.
  809. */
  810. removeEventListeners(eventList) {
  811. eventList.forEach(event => this.removeEventListener(event));
  812. }
  813. /**
  814. * Passes an event along to the local conference participant to establish
  815. * or update a direct peer connection. This is currently used for developing
  816. * wireless screensharing with room integration and it is advised against to
  817. * use as its api may change.
  818. *
  819. * @param {Object} event - An object with information to pass along.
  820. * @param {Object} event.data - The payload of the event.
  821. * @param {string} event.from - The jid of the sender of the event. Needed
  822. * when a reply is to be sent regarding the event.
  823. * @returns {void}
  824. */
  825. sendProxyConnectionEvent(event) {
  826. this._transport.sendEvent({
  827. data: [ event ],
  828. name: 'proxy-connection-event'
  829. });
  830. }
  831. /**
  832. * Sets the audio input device to the one with the label or id that is
  833. * passed.
  834. *
  835. * @param {string} label - The label of the new device.
  836. * @param {string} deviceId - The id of the new device.
  837. * @returns {Promise}
  838. */
  839. setAudioInputDevice(label, deviceId) {
  840. return setAudioInputDevice(this._transport, label, deviceId);
  841. }
  842. /**
  843. * Sets the audio output device to the one with the label or id that is
  844. * passed.
  845. *
  846. * @param {string} label - The label of the new device.
  847. * @param {string} deviceId - The id of the new device.
  848. * @returns {Promise}
  849. */
  850. setAudioOutputDevice(label, deviceId) {
  851. return setAudioOutputDevice(this._transport, label, deviceId);
  852. }
  853. /**
  854. * Sets the video input device to the one with the label or id that is
  855. * passed.
  856. *
  857. * @param {string} label - The label of the new device.
  858. * @param {string} deviceId - The id of the new device.
  859. * @returns {Promise}
  860. */
  861. setVideoInputDevice(label, deviceId) {
  862. return setVideoInputDevice(this._transport, label, deviceId);
  863. }
  864. /**
  865. * Returns the configuration for electron for the windows that are open
  866. * from Jitsi Meet.
  867. *
  868. * @returns {Promise<Object>}
  869. *
  870. * NOTE: For internal use only.
  871. */
  872. _getElectronPopupsConfig() {
  873. return Promise.resolve(electronPopupsConfig);
  874. }
  875. }