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

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