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

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