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

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