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

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