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

external_api.js 28KB

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