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

external_api.js 28KB

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