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

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