You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

external_api.js 33KB

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