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

external_api.js 30KB

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