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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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. * @param {Array<Object>} [options.devices] - Array of objects containing
  206. * information about the initial devices that will be used in the call.
  207. */
  208. constructor(domain, ...args) {
  209. super();
  210. const {
  211. roomName = '',
  212. width = '100%',
  213. height = '100%',
  214. parentNode = document.body,
  215. configOverwrite = {},
  216. interfaceConfigOverwrite = {},
  217. noSSL = false,
  218. jwt = undefined,
  219. onload = undefined,
  220. invitees,
  221. devices
  222. } = parseArguments(args);
  223. this._parentNode = parentNode;
  224. this._url = generateURL(domain, {
  225. configOverwrite,
  226. interfaceConfigOverwrite,
  227. jwt,
  228. noSSL,
  229. roomName,
  230. devices
  231. });
  232. this._createIFrame(height, width, onload);
  233. this._transport = new Transport({
  234. backend: new PostMessageTransportBackend({
  235. postisOptions: {
  236. scope: `jitsi_meet_external_api_${id}`,
  237. window: this._frame.contentWindow
  238. }
  239. })
  240. });
  241. if (Array.isArray(invitees) && invitees.length > 0) {
  242. this.invite(invitees);
  243. }
  244. this._isLargeVideoVisible = true;
  245. this._numberOfParticipants = 0;
  246. this._participants = {};
  247. this._myUserID = undefined;
  248. this._onStageParticipant = undefined;
  249. this._setupListeners();
  250. id++;
  251. }
  252. /**
  253. * Creates the iframe element.
  254. *
  255. * @param {number|string} height - The height of the iframe. Check
  256. * parseSizeParam for format details.
  257. * @param {number|string} width - The with of the iframe. Check
  258. * parseSizeParam for format details.
  259. * @param {Function} onload - The function that will listen
  260. * for onload event.
  261. * @returns {void}
  262. *
  263. * @private
  264. */
  265. _createIFrame(height, width, onload) {
  266. const frameName = `jitsiConferenceFrame${id}`;
  267. this._frame = document.createElement('iframe');
  268. this._frame.allow = 'camera; microphone';
  269. this._frame.src = this._url;
  270. this._frame.name = frameName;
  271. this._frame.id = frameName;
  272. this._setSize(height, width);
  273. this._frame.setAttribute('allowFullScreen', 'true');
  274. this._frame.style.border = 0;
  275. if (onload) {
  276. // waits for iframe resources to load
  277. // and fires event when it is done
  278. this._frame.onload = onload;
  279. }
  280. this._frame = this._parentNode.appendChild(this._frame);
  281. }
  282. /**
  283. * Returns arrays with the all resources for the always on top feature.
  284. *
  285. * @returns {Array<string>}
  286. */
  287. _getAlwaysOnTopResources() {
  288. const iframeWindow = this._frame.contentWindow;
  289. const iframeDocument = iframeWindow.document;
  290. let baseURL = '';
  291. const base = iframeDocument.querySelector('base');
  292. if (base && base.href) {
  293. baseURL = base.href;
  294. } else {
  295. const { protocol, host } = iframeWindow.location;
  296. baseURL = `${protocol}//${host}`;
  297. }
  298. return ALWAYS_ON_TOP_FILENAMES.map(
  299. filename => (new URL(filename, baseURL)).href
  300. );
  301. }
  302. /**
  303. * Returns the id of the on stage participant.
  304. *
  305. * @returns {string} - The id of the on stage participant.
  306. */
  307. _getOnStageParticipant() {
  308. return this._onStageParticipant;
  309. }
  310. /**
  311. * Getter for the large video element in Jitsi Meet.
  312. *
  313. * @returns {HTMLElement|undefined} - The large video.
  314. */
  315. _getLargeVideo() {
  316. const iframe = this.getIFrame();
  317. if (!this._isLargeVideoVisible
  318. || !iframe
  319. || !iframe.contentWindow
  320. || !iframe.contentWindow.document) {
  321. return;
  322. }
  323. return iframe.contentWindow.document.getElementById('largeVideo');
  324. }
  325. /**
  326. * Sets the size of the iframe element.
  327. *
  328. * @param {number|string} height - The height of the iframe.
  329. * @param {number|string} width - The with of the iframe.
  330. * @returns {void}
  331. *
  332. * @private
  333. */
  334. _setSize(height, width) {
  335. const parsedHeight = parseSizeParam(height);
  336. const parsedWidth = parseSizeParam(width);
  337. if (parsedHeight !== undefined) {
  338. this._frame.style.height = parsedHeight;
  339. }
  340. if (parsedWidth !== undefined) {
  341. this._frame.style.width = parsedWidth;
  342. }
  343. }
  344. /**
  345. * Setups listeners that are used internally for JitsiMeetExternalAPI.
  346. *
  347. * @returns {void}
  348. *
  349. * @private
  350. */
  351. _setupListeners() {
  352. this._transport.on('event', ({ name, ...data }) => {
  353. const userID = data.id;
  354. switch (name) {
  355. case 'video-conference-joined':
  356. this._myUserID = userID;
  357. this._participants[userID] = {
  358. avatarURL: data.avatarURL
  359. };
  360. // eslint-disable-next-line no-fallthrough
  361. case 'participant-joined': {
  362. this._participants[userID] = this._participants[userID] || {};
  363. this._participants[userID].displayName = data.displayName;
  364. this._participants[userID].formattedDisplayName
  365. = data.formattedDisplayName;
  366. changeParticipantNumber(this, 1);
  367. break;
  368. }
  369. case 'participant-left':
  370. changeParticipantNumber(this, -1);
  371. delete this._participants[userID];
  372. break;
  373. case 'display-name-change': {
  374. const user = this._participants[userID];
  375. if (user) {
  376. user.displayName = data.displayname;
  377. user.formattedDisplayName = data.formattedDisplayName;
  378. }
  379. break;
  380. }
  381. case 'email-change': {
  382. const user = this._participants[userID];
  383. if (user) {
  384. user.email = data.email;
  385. }
  386. break;
  387. }
  388. case 'avatar-changed': {
  389. const user = this._participants[userID];
  390. if (user) {
  391. user.avatarURL = data.avatarURL;
  392. }
  393. break;
  394. }
  395. case 'on-stage-participant-changed':
  396. this._onStageParticipant = userID;
  397. this.emit('largeVideoChanged');
  398. break;
  399. case 'large-video-visibility-changed':
  400. this._isLargeVideoVisible = data.isVisible;
  401. this.emit('largeVideoChanged');
  402. break;
  403. case 'video-conference-left':
  404. changeParticipantNumber(this, -1);
  405. delete this._participants[this._myUserID];
  406. break;
  407. }
  408. const eventName = events[name];
  409. if (eventName) {
  410. this.emit(eventName, data);
  411. return true;
  412. }
  413. return false;
  414. });
  415. }
  416. /**
  417. * Adds event listener to Meet Jitsi.
  418. *
  419. * @param {string} event - The name of the event.
  420. * @param {Function} listener - The listener.
  421. * @returns {void}
  422. *
  423. * @deprecated
  424. * NOTE: This method is not removed for backward comatability purposes.
  425. */
  426. addEventListener(event, listener) {
  427. this.on(event, listener);
  428. }
  429. /**
  430. * Adds event listeners to Meet Jitsi.
  431. *
  432. * @param {Object} listeners - The object key should be the name of
  433. * the event and value - the listener.
  434. * Currently we support the following
  435. * events:
  436. * {@code incomingMessage} - receives event notifications about incoming
  437. * messages. The listener will receive object with the following structure:
  438. * {{
  439. * 'from': from,//JID of the user that sent the message
  440. * 'nick': nick,//the nickname of the user that sent the message
  441. * 'message': txt//the text of the message
  442. * }}
  443. * {@code outgoingMessage} - receives event notifications about outgoing
  444. * messages. The listener will receive object with the following structure:
  445. * {{
  446. * 'message': txt//the text of the message
  447. * }}
  448. * {@code displayNameChanged} - receives event notifications about display
  449. * name change. The listener will receive object with the following
  450. * structure:
  451. * {{
  452. * jid: jid,//the JID of the participant that changed his display name
  453. * displayname: displayName //the new display name
  454. * }}
  455. * {@code participantJoined} - receives event notifications about new
  456. * participant.
  457. * The listener will receive object with the following structure:
  458. * {{
  459. * jid: jid //the jid of the participant
  460. * }}
  461. * {@code participantLeft} - receives event notifications about the
  462. * participant that left the room.
  463. * The listener will receive object with the following structure:
  464. * {{
  465. * jid: jid //the jid of the participant
  466. * }}
  467. * {@code video-conference-joined} - receives event notifications about the
  468. * local user has successfully joined the video conference.
  469. * The listener will receive object with the following structure:
  470. * {{
  471. * roomName: room //the room name of the conference
  472. * }}
  473. * {@code video-conference-left} - receives event notifications about the
  474. * local user has left the video conference.
  475. * The listener will receive object with the following structure:
  476. * {{
  477. * roomName: room //the room name of the conference
  478. * }}
  479. * {@code screenSharingStatusChanged} - receives event notifications about
  480. * turning on/off the local user screen sharing.
  481. * The listener will receive object with the following structure:
  482. * {{
  483. * on: on //whether screen sharing is on
  484. * }}
  485. * {@code readyToClose} - all hangup operations are completed and Jitsi Meet
  486. * is ready to be disposed.
  487. * @returns {void}
  488. *
  489. * @deprecated
  490. * NOTE: This method is not removed for backward comatability purposes.
  491. */
  492. addEventListeners(listeners) {
  493. for (const event in listeners) { // eslint-disable-line guard-for-in
  494. this.addEventListener(event, listeners[event]);
  495. }
  496. }
  497. /**
  498. * Removes the listeners and removes the Jitsi Meet frame.
  499. *
  500. * @returns {void}
  501. */
  502. dispose() {
  503. this.emit('_willDispose');
  504. this._transport.dispose();
  505. this.removeAllListeners();
  506. if (this._frame) {
  507. this._frame.parentNode.removeChild(this._frame);
  508. }
  509. }
  510. /**
  511. * Executes command. The available commands are:
  512. * {@code displayName} - Sets the display name of the local participant to
  513. * the value passed in the arguments array.
  514. * {@code subject} - Sets the subject of the conference, the value passed
  515. * in the arguments array. Note: Available only for moderator.
  516. *
  517. * {@code toggleAudio} - Mutes / unmutes audio with no arguments.
  518. * {@code toggleVideo} - Mutes / unmutes video with no arguments.
  519. * {@code toggleFilmStrip} - Hides / shows the filmstrip with no arguments.
  520. *
  521. * If the command doesn't require any arguments the parameter should be set
  522. * to empty array or it may be omitted.
  523. *
  524. * @param {string} name - The name of the command.
  525. * @returns {void}
  526. */
  527. executeCommand(name, ...args) {
  528. if (!(name in commands)) {
  529. logger.error('Not supported command name.');
  530. return;
  531. }
  532. this._transport.sendEvent({
  533. data: args,
  534. name: commands[name]
  535. });
  536. }
  537. /**
  538. * Executes commands. The available commands are:
  539. * {@code displayName} - Sets the display name of the local participant to
  540. * the value passed in the arguments array.
  541. * {@code toggleAudio} - Mutes / unmutes audio. No arguments.
  542. * {@code toggleVideo} - Mutes / unmutes video. No arguments.
  543. * {@code toggleFilmStrip} - Hides / shows the filmstrip. No arguments.
  544. * {@code toggleChat} - Hides / shows chat. No arguments.
  545. * {@code toggleShareScreen} - Starts / stops screen sharing. No arguments.
  546. *
  547. * @param {Object} commandList - The object with commands to be executed.
  548. * The keys of the object are the commands that will be executed and the
  549. * values are the arguments for the command.
  550. * @returns {void}
  551. */
  552. executeCommands(commandList) {
  553. for (const key in commandList) { // eslint-disable-line guard-for-in
  554. this.executeCommand(key, commandList[key]);
  555. }
  556. }
  557. /**
  558. * Returns Promise that resolves with result an list of available devices.
  559. *
  560. * @returns {Promise}
  561. */
  562. getAvailableDevices() {
  563. return getAvailableDevices(this._transport);
  564. }
  565. /**
  566. * Returns Promise that resolves with current selected devices.
  567. *
  568. * @returns {Promise}
  569. */
  570. getCurrentDevices() {
  571. return getCurrentDevices(this._transport);
  572. }
  573. /**
  574. * Check if the audio is available.
  575. *
  576. * @returns {Promise} - Resolves with true if the audio available, with
  577. * false if not and rejects on failure.
  578. */
  579. isAudioAvailable() {
  580. return this._transport.sendRequest({
  581. name: 'is-audio-available'
  582. });
  583. }
  584. /**
  585. * Returns Promise that resolves with true if the device change is available
  586. * and with false if not.
  587. *
  588. * @param {string} [deviceType] - Values - 'output', 'input' or undefined.
  589. * Default - 'input'.
  590. * @returns {Promise}
  591. */
  592. isDeviceChangeAvailable(deviceType) {
  593. return isDeviceChangeAvailable(this._transport, deviceType);
  594. }
  595. /**
  596. * Returns Promise that resolves with true if the device list is available
  597. * and with false if not.
  598. *
  599. * @returns {Promise}
  600. */
  601. isDeviceListAvailable() {
  602. return isDeviceListAvailable(this._transport);
  603. }
  604. /**
  605. * Returns Promise that resolves with true if the device list is available
  606. * and with false if not.
  607. *
  608. * @returns {Promise}
  609. */
  610. isMultipleAudioInputSupported() {
  611. return isMultipleAudioInputSupported(this._transport);
  612. }
  613. /**
  614. * Invite people to the call.
  615. *
  616. * @param {Array<Object>} invitees - The invitees.
  617. * @returns {Promise} - Resolves on success and rejects on failure.
  618. */
  619. invite(invitees) {
  620. if (!Array.isArray(invitees) || invitees.length === 0) {
  621. return Promise.reject(new TypeError('Invalid Argument'));
  622. }
  623. return this._transport.sendRequest({
  624. name: 'invite',
  625. invitees
  626. });
  627. }
  628. /**
  629. * Returns the audio mute status.
  630. *
  631. * @returns {Promise} - Resolves with the audio mute status and rejects on
  632. * failure.
  633. */
  634. isAudioMuted() {
  635. return this._transport.sendRequest({
  636. name: 'is-audio-muted'
  637. });
  638. }
  639. /**
  640. * Returns the avatar URL of a participant.
  641. *
  642. * @param {string} participantId - The id of the participant.
  643. * @returns {string} The avatar URL.
  644. */
  645. getAvatarURL(participantId) {
  646. const { avatarURL } = this._participants[participantId] || {};
  647. return avatarURL;
  648. }
  649. /**
  650. * Returns the display name of a participant.
  651. *
  652. * @param {string} participantId - The id of the participant.
  653. * @returns {string} The display name.
  654. */
  655. getDisplayName(participantId) {
  656. const { displayName } = this._participants[participantId] || {};
  657. return displayName;
  658. }
  659. /**
  660. * Returns the email of a participant.
  661. *
  662. * @param {string} participantId - The id of the participant.
  663. * @returns {string} The email.
  664. */
  665. getEmail(participantId) {
  666. const { email } = this._participants[participantId] || {};
  667. return email;
  668. }
  669. /**
  670. * Returns the formatted display name of a participant.
  671. *
  672. * @param {string} participantId - The id of the participant.
  673. * @returns {string} The formatted display name.
  674. */
  675. _getFormattedDisplayName(participantId) {
  676. const { formattedDisplayName }
  677. = this._participants[participantId] || {};
  678. return formattedDisplayName;
  679. }
  680. /**
  681. * Returns the iframe that loads Jitsi Meet.
  682. *
  683. * @returns {HTMLElement} The iframe.
  684. */
  685. getIFrame() {
  686. return this._frame;
  687. }
  688. /**
  689. * Returns the number of participants in the conference. The local
  690. * participant is included.
  691. *
  692. * @returns {int} The number of participants in the conference.
  693. */
  694. getNumberOfParticipants() {
  695. return this._numberOfParticipants;
  696. }
  697. /**
  698. * Check if the video is available.
  699. *
  700. * @returns {Promise} - Resolves with true if the video available, with
  701. * false if not and rejects on failure.
  702. */
  703. isVideoAvailable() {
  704. return this._transport.sendRequest({
  705. name: 'is-video-available'
  706. });
  707. }
  708. /**
  709. * Returns the audio mute status.
  710. *
  711. * @returns {Promise} - Resolves with the audio mute status and rejects on
  712. * failure.
  713. */
  714. isVideoMuted() {
  715. return this._transport.sendRequest({
  716. name: 'is-video-muted'
  717. });
  718. }
  719. /**
  720. * Removes event listener.
  721. *
  722. * @param {string} event - The name of the event.
  723. * @returns {void}
  724. *
  725. * @deprecated
  726. * NOTE: This method is not removed for backward comatability purposes.
  727. */
  728. removeEventListener(event) {
  729. this.removeAllListeners(event);
  730. }
  731. /**
  732. * Removes event listeners.
  733. *
  734. * @param {Array<string>} eventList - Array with the names of the events.
  735. * @returns {void}
  736. *
  737. * @deprecated
  738. * NOTE: This method is not removed for backward comatability purposes.
  739. */
  740. removeEventListeners(eventList) {
  741. eventList.forEach(event => this.removeEventListener(event));
  742. }
  743. /**
  744. * Passes an event along to the local conference participant to establish
  745. * or update a direct peer connection. This is currently used for developing
  746. * wireless screensharing with room integration and it is advised against to
  747. * use as its api may change.
  748. *
  749. * @param {Object} event - An object with information to pass along.
  750. * @param {Object} event.data - The payload of the event.
  751. * @param {string} event.from - The jid of the sender of the event. Needed
  752. * when a reply is to be sent regarding the event.
  753. * @returns {void}
  754. */
  755. sendProxyConnectionEvent(event) {
  756. this._transport.sendEvent({
  757. data: [ event ],
  758. name: 'proxy-connection-event'
  759. });
  760. }
  761. /**
  762. * Sets the audio input device to the one with the id that is passed.
  763. *
  764. * @param {string} deviceId - The id of the new device.
  765. * @returns {Promise}
  766. */
  767. setAudioInputDevice(deviceId) {
  768. return setAudioInputDevice(this._transport, deviceId);
  769. }
  770. /**
  771. * Sets the audio output device to the one with the id that is passed.
  772. *
  773. * @param {string} deviceId - The id of the new device.
  774. * @returns {Promise}
  775. */
  776. setAudioOutputDevice(deviceId) {
  777. return setAudioOutputDevice(this._transport, deviceId);
  778. }
  779. /**
  780. * Sets the video input device to the one with the id that is passed.
  781. *
  782. * @param {string} deviceId - The id of the new device.
  783. * @returns {Promise}
  784. */
  785. setVideoInputDevice(deviceId) {
  786. return setVideoInputDevice(this._transport, deviceId);
  787. }
  788. /**
  789. * Returns the configuration for electron for the windows that are open
  790. * from Jitsi Meet.
  791. *
  792. * @returns {Promise<Object>}
  793. *
  794. * NOTE: For internal use only.
  795. */
  796. _getElectronPopupsConfig() {
  797. return Promise.resolve(electronPopupsConfig);
  798. }
  799. }