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

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