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

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