You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

external_api.js 28KB

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