您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

external_api.js 31KB

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