您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

external_api.js 28KB

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