Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

external_api.js 30KB

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