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

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