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

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