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

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