Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

external_api.js 30KB

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