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

external_api.js 29KB

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