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

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