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 31KB

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