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

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