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 30KB

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