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 35KB

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