You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

external_api.js 29KB

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