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

external_api.js 36KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  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. avatarUrl: 'avatar-url',
  27. cancelPrivateChat: 'cancel-private-chat',
  28. displayName: 'display-name',
  29. e2eeKey: 'e2ee-key',
  30. email: 'email',
  31. toggleLobby: 'toggle-lobby',
  32. hangup: 'video-hangup',
  33. intiatePrivateChat: 'initiate-private-chat',
  34. kickParticipant: 'kick-participant',
  35. muteEveryone: 'mute-everyone',
  36. overwriteConfig: 'overwrite-config',
  37. password: 'password',
  38. pinParticipant: 'pin-participant',
  39. resizeLargeVideo: 'resize-large-video',
  40. sendEndpointTextMessage: 'send-endpoint-text-message',
  41. sendTones: 'send-tones',
  42. setLargeVideoParticipant: 'set-large-video-participant',
  43. setTileView: 'set-tile-view',
  44. setVideoQuality: 'set-video-quality',
  45. startRecording: 'start-recording',
  46. stopRecording: 'stop-recording',
  47. subject: 'subject',
  48. submitFeedback: 'submit-feedback',
  49. toggleAudio: 'toggle-audio',
  50. toggleChat: 'toggle-chat',
  51. toggleFilmStrip: 'toggle-film-strip',
  52. toggleRaiseHand: 'toggle-raise-hand',
  53. toggleShareScreen: 'toggle-share-screen',
  54. toggleTileView: 'toggle-tile-view',
  55. toggleVideo: 'toggle-video'
  56. };
  57. /**
  58. * Maps the names of the events expected by the API with the name of the
  59. * events expected by jitsi-meet
  60. */
  61. const events = {
  62. 'avatar-changed': 'avatarChanged',
  63. 'audio-availability-changed': 'audioAvailabilityChanged',
  64. 'audio-mute-status-changed': 'audioMuteStatusChanged',
  65. 'camera-error': 'cameraError',
  66. 'chat-updated': 'chatUpdated',
  67. 'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
  68. 'device-list-changed': 'deviceListChanged',
  69. 'display-name-change': 'displayNameChange',
  70. 'email-change': 'emailChange',
  71. 'endpoint-text-message-received': 'endpointTextMessageReceived',
  72. 'feedback-submitted': 'feedbackSubmitted',
  73. 'feedback-prompt-displayed': 'feedbackPromptDisplayed',
  74. 'filmstrip-display-changed': 'filmstripDisplayChanged',
  75. 'incoming-message': 'incomingMessage',
  76. 'log': 'log',
  77. 'mic-error': 'micError',
  78. 'outgoing-message': 'outgoingMessage',
  79. 'participant-joined': 'participantJoined',
  80. 'participant-kicked-out': 'participantKickedOut',
  81. 'participant-left': 'participantLeft',
  82. 'participant-role-changed': 'participantRoleChanged',
  83. 'password-required': 'passwordRequired',
  84. 'proxy-connection-event': 'proxyConnectionEvent',
  85. 'raise-hand-updated': 'raiseHandUpdated',
  86. 'recording-status-changed': 'recordingStatusChanged',
  87. 'video-ready-to-close': 'readyToClose',
  88. 'video-conference-joined': 'videoConferenceJoined',
  89. 'video-conference-left': 'videoConferenceLeft',
  90. 'video-availability-changed': 'videoAvailabilityChanged',
  91. 'video-mute-status-changed': 'videoMuteStatusChanged',
  92. 'video-quality-changed': 'videoQualityChanged',
  93. 'screen-sharing-status-changed': 'screenSharingStatusChanged',
  94. 'dominant-speaker-changed': 'dominantSpeakerChanged',
  95. 'subject-change': 'subjectChange',
  96. 'suspend-detected': 'suspendDetected',
  97. 'tile-view-changed': 'tileViewChanged'
  98. };
  99. /**
  100. * Last id of api object
  101. * @type {number}
  102. */
  103. let id = 0;
  104. /**
  105. * Adds given number to the numberOfParticipants property of given APIInstance.
  106. *
  107. * @param {JitsiMeetExternalAPI} APIInstance - The instance of the API.
  108. * @param {int} number - The number of participants to be added to
  109. * numberOfParticipants property (this parameter can be negative number if the
  110. * numberOfParticipants should be decreased).
  111. * @returns {void}
  112. */
  113. function changeParticipantNumber(APIInstance, number) {
  114. APIInstance._numberOfParticipants += number;
  115. }
  116. /**
  117. * Generates the URL for the iframe.
  118. *
  119. * @param {string} domain - The domain name of the server that hosts the
  120. * conference.
  121. * @param {string} [options] - Another optional parameters.
  122. * @param {Object} [options.configOverwrite] - Object containing configuration
  123. * options defined in config.js to be overridden.
  124. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  125. * configuration options defined in interface_config.js to be overridden.
  126. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  127. * authentication.
  128. * @param {string} [options.roomName] - The name of the room to join.
  129. * @returns {string} The URL.
  130. */
  131. function generateURL(domain, options = {}) {
  132. return urlObjectToString({
  133. ...options,
  134. url: `https://${domain}/#jitsi_meet_external_api_id=${id}`
  135. });
  136. }
  137. /**
  138. * Parses the arguments passed to the constructor. If the old format is used
  139. * the function translates the arguments to the new format.
  140. *
  141. * @param {Array} args - The arguments to be parsed.
  142. * @returns {Object} JS object with properties.
  143. */
  144. function parseArguments(args) {
  145. if (!args.length) {
  146. return {};
  147. }
  148. const firstArg = args[0];
  149. switch (typeof firstArg) {
  150. case 'string': // old arguments format
  151. case undefined: {
  152. // Not sure which format but we are trying to parse the old
  153. // format because if the new format is used everything will be undefined
  154. // anyway.
  155. const [
  156. roomName,
  157. width,
  158. height,
  159. parentNode,
  160. configOverwrite,
  161. interfaceConfigOverwrite,
  162. jwt,
  163. onload
  164. ] = args;
  165. return {
  166. roomName,
  167. width,
  168. height,
  169. parentNode,
  170. configOverwrite,
  171. interfaceConfigOverwrite,
  172. jwt,
  173. onload
  174. };
  175. }
  176. case 'object': // new arguments format
  177. return args[0];
  178. default:
  179. throw new Error('Can\'t parse the arguments!');
  180. }
  181. }
  182. /**
  183. * Compute valid values for height and width. If a number is specified it's
  184. * treated as pixel units. If the value is expressed in px, em, pt or
  185. * percentage, it's used as is.
  186. *
  187. * @param {any} value - The value to be parsed.
  188. * @returns {string|undefined} The parsed value that can be used for setting
  189. * sizes through the style property. If invalid value is passed the method
  190. * returns undefined.
  191. */
  192. function parseSizeParam(value) {
  193. let parsedValue;
  194. // This regex parses values of the form 100px, 100em, 100pt or 100%.
  195. // Values like 100 or 100px are handled outside of the regex, and
  196. // invalid values will be ignored and the minimum will be used.
  197. const re = /([0-9]*\.?[0-9]+)(em|pt|px|%)$/;
  198. if (typeof value === 'string' && String(value).match(re) !== null) {
  199. parsedValue = value;
  200. } else if (typeof value === 'number') {
  201. parsedValue = `${value}px`;
  202. }
  203. return parsedValue;
  204. }
  205. /**
  206. * The IFrame API interface class.
  207. */
  208. export default class JitsiMeetExternalAPI extends EventEmitter {
  209. /**
  210. * Constructs new API instance. Creates iframe and loads Jitsi Meet in it.
  211. *
  212. * @param {string} domain - The domain name of the server that hosts the
  213. * conference.
  214. * @param {Object} [options] - Optional arguments.
  215. * @param {string} [options.roomName] - The name of the room to join.
  216. * @param {number|string} [options.width] - Width of the iframe. Check
  217. * parseSizeParam for format details.
  218. * @param {number|string} [options.height] - Height of the iframe. Check
  219. * parseSizeParam for format details.
  220. * @param {DOMElement} [options.parentNode] - The node that will contain the
  221. * iframe.
  222. * @param {Object} [options.configOverwrite] - Object containing
  223. * configuration options defined in config.js to be overridden.
  224. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  225. * configuration options defined in interface_config.js to be overridden.
  226. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  227. * authentication.
  228. * @param {string} [options.onload] - The onload function that will listen
  229. * for iframe onload event.
  230. * @param {Array<Object>} [options.invitees] - Array of objects containing
  231. * information about new participants that will be invited in the call.
  232. * @param {Array<Object>} [options.devices] - Array of objects containing
  233. * information about the initial devices that will be used in the call.
  234. * @param {Object} [options.userInfo] - Object containing information about
  235. * the participant opening the meeting.
  236. * @param {string} [options.e2eeKey] - The key used for End-to-End encryption.
  237. * THIS IS EXPERIMENTAL.
  238. */
  239. constructor(domain, ...args) {
  240. super();
  241. const {
  242. roomName = '',
  243. width = '100%',
  244. height = '100%',
  245. parentNode = document.body,
  246. configOverwrite = {},
  247. interfaceConfigOverwrite = {},
  248. jwt = undefined,
  249. onload = undefined,
  250. invitees,
  251. devices,
  252. userInfo,
  253. e2eeKey
  254. } = parseArguments(args);
  255. const localStorageContent = jitsiLocalStorage.getItem('jitsiLocalStorage');
  256. this._parentNode = parentNode;
  257. this._url = generateURL(domain, {
  258. configOverwrite,
  259. interfaceConfigOverwrite,
  260. jwt,
  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; autoplay; clipboard-write';
  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 chatUpdated} - receives event notifications about chat state being
  527. * updated. The listener will receive object with the following structure:
  528. * {{
  529. * 'unreadCount': unreadCounter, // the unread message(s) counter,
  530. * 'isOpen': isOpen, // whether the chat panel is open or not
  531. * }}
  532. * {@code incomingMessage} - receives event notifications about incoming
  533. * messages. The listener will receive object with the following structure:
  534. * {{
  535. * 'from': from,//JID of the user that sent the message
  536. * 'nick': nick,//the nickname of the user that sent the message
  537. * 'message': txt//the text of the message
  538. * }}
  539. * {@code outgoingMessage} - receives event notifications about outgoing
  540. * messages. The listener will receive object with the following structure:
  541. * {{
  542. * 'message': txt//the text of the message
  543. * }}
  544. * {@code displayNameChanged} - receives event notifications about display
  545. * name change. The listener will receive object with the following
  546. * structure:
  547. * {{
  548. * jid: jid,//the JID of the participant that changed his display name
  549. * displayname: displayName //the new display name
  550. * }}
  551. * {@code participantJoined} - receives event notifications about new
  552. * participant.
  553. * The listener will receive object with the following structure:
  554. * {{
  555. * jid: jid //the jid of the participant
  556. * }}
  557. * {@code participantLeft} - receives event notifications about the
  558. * participant that left the room.
  559. * The listener will receive object with the following structure:
  560. * {{
  561. * jid: jid //the jid of the participant
  562. * }}
  563. * {@code videoConferenceJoined} - receives event notifications about the
  564. * local user has successfully joined 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 videoConferenceLeft} - receives event notifications about the
  570. * local user has left the video conference.
  571. * The listener will receive object with the following structure:
  572. * {{
  573. * roomName: room //the room name of the conference
  574. * }}
  575. * {@code screenSharingStatusChanged} - receives event notifications about
  576. * turning on/off the local user screen sharing.
  577. * The listener will receive object with the following structure:
  578. * {{
  579. * on: on //whether screen sharing is on
  580. * }}
  581. * {@code dominantSpeakerChanged} - receives event notifications about
  582. * change in the dominant speaker.
  583. * The listener will receive object with the following structure:
  584. * {{
  585. * id: participantId //participantId of the new dominant speaker
  586. * }}
  587. * {@code suspendDetected} - receives event notifications about detecting suspend event in host computer.
  588. * {@code readyToClose} - all hangup operations are completed and Jitsi Meet
  589. * is ready to be disposed.
  590. * @returns {void}
  591. *
  592. * @deprecated
  593. * NOTE: This method is not removed for backward comatability purposes.
  594. */
  595. addEventListeners(listeners) {
  596. for (const event in listeners) { // eslint-disable-line guard-for-in
  597. this.addEventListener(event, listeners[event]);
  598. }
  599. }
  600. /**
  601. * Captures the screenshot of the large video.
  602. *
  603. * @returns {Promise<string>} - Resolves with a base64 encoded image data of the screenshot
  604. * if large video is detected, an error otherwise.
  605. */
  606. captureLargeVideoScreenshot() {
  607. return this._transport.sendRequest({
  608. name: 'capture-largevideo-screenshot'
  609. });
  610. }
  611. /**
  612. * Removes the listeners and removes the Jitsi Meet frame.
  613. *
  614. * @returns {void}
  615. */
  616. dispose() {
  617. this.emit('_willDispose');
  618. this._transport.dispose();
  619. this.removeAllListeners();
  620. if (this._frame && this._frame.parentNode) {
  621. this._frame.parentNode.removeChild(this._frame);
  622. }
  623. }
  624. /**
  625. * Executes command. The available commands are:
  626. * {@code displayName} - Sets the display name of the local participant to
  627. * the value passed in the arguments array.
  628. * {@code subject} - Sets the subject of the conference, the value passed
  629. * in the arguments array. Note: Available only for moderator.
  630. *
  631. * {@code toggleAudio} - Mutes / unmutes audio with no arguments.
  632. * {@code toggleVideo} - Mutes / unmutes video with no arguments.
  633. * {@code toggleFilmStrip} - Hides / shows the filmstrip with no arguments.
  634. *
  635. * If the command doesn't require any arguments the parameter should be set
  636. * to empty array or it may be omitted.
  637. *
  638. * @param {string} name - The name of the command.
  639. * @returns {void}
  640. */
  641. executeCommand(name, ...args) {
  642. if (!(name in commands)) {
  643. console.error('Not supported command name.');
  644. return;
  645. }
  646. this._transport.sendEvent({
  647. data: args,
  648. name: commands[name]
  649. });
  650. }
  651. /**
  652. * Executes commands. The available commands are:
  653. * {@code displayName} - Sets the display name of the local participant to
  654. * the value passed in the arguments array.
  655. * {@code toggleAudio} - Mutes / unmutes audio. No arguments.
  656. * {@code toggleVideo} - Mutes / unmutes video. No arguments.
  657. * {@code toggleFilmStrip} - Hides / shows the filmstrip. No arguments.
  658. * {@code toggleChat} - Hides / shows chat. No arguments.
  659. * {@code toggleShareScreen} - Starts / stops screen sharing. No arguments.
  660. *
  661. * @param {Object} commandList - The object with commands to be executed.
  662. * The keys of the object are the commands that will be executed and the
  663. * values are the arguments for the command.
  664. * @returns {void}
  665. */
  666. executeCommands(commandList) {
  667. for (const key in commandList) { // eslint-disable-line guard-for-in
  668. this.executeCommand(key, commandList[key]);
  669. }
  670. }
  671. /**
  672. * Returns Promise that resolves with a list of available devices.
  673. *
  674. * @returns {Promise}
  675. */
  676. getAvailableDevices() {
  677. return getAvailableDevices(this._transport);
  678. }
  679. /**
  680. * Gets a list of the currently sharing participant id's.
  681. *
  682. * @returns {Promise} - Resolves with the list of participant id's currently sharing.
  683. */
  684. getContentSharingParticipants() {
  685. return this._transport.sendRequest({
  686. name: 'get-content-sharing-participants'
  687. });
  688. }
  689. /**
  690. * Returns Promise that resolves with current selected devices.
  691. *
  692. * @returns {Promise}
  693. */
  694. getCurrentDevices() {
  695. return getCurrentDevices(this._transport);
  696. }
  697. /**
  698. * Returns the current livestream url.
  699. *
  700. * @returns {Promise} - Resolves with the current livestream URL if exists, with
  701. * undefined if not and rejects on failure.
  702. */
  703. getLivestreamUrl() {
  704. return this._transport.sendRequest({
  705. name: 'get-livestream-url'
  706. });
  707. }
  708. /**
  709. * Returns the conference participants information.
  710. *
  711. * @returns {Array<Object>} - Returns an array containing participants
  712. * information like participant id, display name, avatar URL and email.
  713. */
  714. getParticipantsInfo() {
  715. const participantIds = Object.keys(this._participants);
  716. const participantsInfo = Object.values(this._participants);
  717. participantsInfo.forEach((participant, idx) => {
  718. participant.participantId = participantIds[idx];
  719. });
  720. return participantsInfo;
  721. }
  722. /**
  723. * Returns the current video quality setting.
  724. *
  725. * @returns {number}
  726. */
  727. getVideoQuality() {
  728. return this._videoQuality;
  729. }
  730. /**
  731. * Check if the audio is available.
  732. *
  733. * @returns {Promise} - Resolves with true if the audio available, with
  734. * false if not and rejects on failure.
  735. */
  736. isAudioAvailable() {
  737. return this._transport.sendRequest({
  738. name: 'is-audio-available'
  739. });
  740. }
  741. /**
  742. * Returns Promise that resolves with true if the device change is available
  743. * and with false if not.
  744. *
  745. * @param {string} [deviceType] - Values - 'output', 'input' or undefined.
  746. * Default - 'input'.
  747. * @returns {Promise}
  748. */
  749. isDeviceChangeAvailable(deviceType) {
  750. return isDeviceChangeAvailable(this._transport, deviceType);
  751. }
  752. /**
  753. * Returns Promise that resolves with true if the device list is available
  754. * and with false if not.
  755. *
  756. * @returns {Promise}
  757. */
  758. isDeviceListAvailable() {
  759. return isDeviceListAvailable(this._transport);
  760. }
  761. /**
  762. * Returns Promise that resolves with true if multiple audio input is supported
  763. * and with false if not.
  764. *
  765. * @returns {Promise}
  766. */
  767. isMultipleAudioInputSupported() {
  768. return isMultipleAudioInputSupported(this._transport);
  769. }
  770. /**
  771. * Invite people to the call.
  772. *
  773. * @param {Array<Object>} invitees - The invitees.
  774. * @returns {Promise} - Resolves on success and rejects on failure.
  775. */
  776. invite(invitees) {
  777. if (!Array.isArray(invitees) || invitees.length === 0) {
  778. return Promise.reject(new TypeError('Invalid Argument'));
  779. }
  780. return this._transport.sendRequest({
  781. name: 'invite',
  782. invitees
  783. });
  784. }
  785. /**
  786. * Returns the audio mute status.
  787. *
  788. * @returns {Promise} - Resolves with the audio mute status and rejects on
  789. * failure.
  790. */
  791. isAudioMuted() {
  792. return this._transport.sendRequest({
  793. name: 'is-audio-muted'
  794. });
  795. }
  796. /**
  797. * Returns screen sharing status.
  798. *
  799. * @returns {Promise} - Resolves with screensharing status and rejects on failure.
  800. */
  801. isSharingScreen() {
  802. return this._transport.sendRequest({
  803. name: 'is-sharing-screen'
  804. });
  805. }
  806. /**
  807. * Returns the avatar URL of a participant.
  808. *
  809. * @param {string} participantId - The id of the participant.
  810. * @returns {string} The avatar URL.
  811. */
  812. getAvatarURL(participantId) {
  813. const { avatarURL } = this._participants[participantId] || {};
  814. return avatarURL;
  815. }
  816. /**
  817. * Returns the display name of a participant.
  818. *
  819. * @param {string} participantId - The id of the participant.
  820. * @returns {string} The display name.
  821. */
  822. getDisplayName(participantId) {
  823. const { displayName } = this._participants[participantId] || {};
  824. return displayName;
  825. }
  826. /**
  827. * Returns the email of a participant.
  828. *
  829. * @param {string} participantId - The id of the participant.
  830. * @returns {string} The email.
  831. */
  832. getEmail(participantId) {
  833. const { email } = this._participants[participantId] || {};
  834. return email;
  835. }
  836. /**
  837. * Returns the iframe that loads Jitsi Meet.
  838. *
  839. * @returns {HTMLElement} The iframe.
  840. */
  841. getIFrame() {
  842. return this._frame;
  843. }
  844. /**
  845. * Returns the number of participants in the conference. The local
  846. * participant is included.
  847. *
  848. * @returns {int} The number of participants in the conference.
  849. */
  850. getNumberOfParticipants() {
  851. return this._numberOfParticipants;
  852. }
  853. /**
  854. * Check if the video is available.
  855. *
  856. * @returns {Promise} - Resolves with true if the video available, with
  857. * false if not and rejects on failure.
  858. */
  859. isVideoAvailable() {
  860. return this._transport.sendRequest({
  861. name: 'is-video-available'
  862. });
  863. }
  864. /**
  865. * Returns the audio mute status.
  866. *
  867. * @returns {Promise} - Resolves with the audio mute status and rejects on
  868. * failure.
  869. */
  870. isVideoMuted() {
  871. return this._transport.sendRequest({
  872. name: 'is-video-muted'
  873. });
  874. }
  875. /**
  876. * Pins a participant's video on to the stage view.
  877. *
  878. * @param {string} participantId - Participant id (JID) of the participant
  879. * that needs to be pinned on the stage view.
  880. * @returns {void}
  881. */
  882. pinParticipant(participantId) {
  883. this.executeCommand('pinParticipant', participantId);
  884. }
  885. /**
  886. * Removes event listener.
  887. *
  888. * @param {string} event - The name of the event.
  889. * @returns {void}
  890. *
  891. * @deprecated
  892. * NOTE: This method is not removed for backward comatability purposes.
  893. */
  894. removeEventListener(event) {
  895. this.removeAllListeners(event);
  896. }
  897. /**
  898. * Removes event listeners.
  899. *
  900. * @param {Array<string>} eventList - Array with the names of the events.
  901. * @returns {void}
  902. *
  903. * @deprecated
  904. * NOTE: This method is not removed for backward comatability purposes.
  905. */
  906. removeEventListeners(eventList) {
  907. eventList.forEach(event => this.removeEventListener(event));
  908. }
  909. /**
  910. * Resizes the large video container as per the dimensions provided.
  911. *
  912. * @param {number} width - Width that needs to be applied on the large video container.
  913. * @param {number} height - Height that needs to be applied on the large video container.
  914. * @returns {void}
  915. */
  916. resizeLargeVideo(width, height) {
  917. if (width <= this._width && height <= this._height) {
  918. this.executeCommand('resizeLargeVideo', width, height);
  919. }
  920. }
  921. /**
  922. * Passes an event along to the local conference participant to establish
  923. * or update a direct peer connection. This is currently used for developing
  924. * wireless screensharing with room integration and it is advised against to
  925. * use as its api may change.
  926. *
  927. * @param {Object} event - An object with information to pass along.
  928. * @param {Object} event.data - The payload of the event.
  929. * @param {string} event.from - The jid of the sender of the event. Needed
  930. * when a reply is to be sent regarding the event.
  931. * @returns {void}
  932. */
  933. sendProxyConnectionEvent(event) {
  934. this._transport.sendEvent({
  935. data: [ event ],
  936. name: 'proxy-connection-event'
  937. });
  938. }
  939. /**
  940. * Sets the audio input device to the one with the label or id that is
  941. * passed.
  942. *
  943. * @param {string} label - The label of the new device.
  944. * @param {string} deviceId - The id of the new device.
  945. * @returns {Promise}
  946. */
  947. setAudioInputDevice(label, deviceId) {
  948. return setAudioInputDevice(this._transport, label, deviceId);
  949. }
  950. /**
  951. * Sets the audio output device to the one with the label or id that is
  952. * passed.
  953. *
  954. * @param {string} label - The label of the new device.
  955. * @param {string} deviceId - The id of the new device.
  956. * @returns {Promise}
  957. */
  958. setAudioOutputDevice(label, deviceId) {
  959. return setAudioOutputDevice(this._transport, label, deviceId);
  960. }
  961. /**
  962. * Displays the given participant on the large video. If no participant id is specified,
  963. * dominant and pinned speakers will be taken into consideration while selecting the
  964. * the large video participant.
  965. *
  966. * @param {string} participantId - Jid of the participant to be displayed on the large video.
  967. * @returns {void}
  968. */
  969. setLargeVideoParticipant(participantId) {
  970. this.executeCommand('setLargeVideoParticipant', participantId);
  971. }
  972. /**
  973. * Sets the video input device to the one with the label or id that is
  974. * passed.
  975. *
  976. * @param {string} label - The label of the new device.
  977. * @param {string} deviceId - The id of the new device.
  978. * @returns {Promise}
  979. */
  980. setVideoInputDevice(label, deviceId) {
  981. return setVideoInputDevice(this._transport, label, deviceId);
  982. }
  983. /**
  984. * Starts a file recording or streaming session depending on the passed on params.
  985. * For RTMP streams, `rtmpStreamKey` must be passed on. `rtmpBroadcastID` is optional.
  986. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  987. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  988. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  989. * No other params should be passed.
  990. *
  991. * @param {Object} options - An object with config options to pass along.
  992. * @param { string } options.mode - Recording mode, either `file` or `stream`.
  993. * @param { string } options.dropboxToken - Dropbox oauth2 token.
  994. * @param { boolean } options.shouldShare - Whether the recording should be shared with the participants or not.
  995. * Only applies to certain jitsi meet deploys.
  996. * @param { string } options.rtmpStreamKey - The RTMP stream key.
  997. * @param { string } options.rtmpBroadcastID - The RTMP broacast ID.
  998. * @param { string } options.youtubeStreamKey - The youtube stream key.
  999. * @param { string } options.youtubeBroadcastID - The youtube broacast ID.
  1000. * @returns {void}
  1001. */
  1002. startRecording(options) {
  1003. this.executeCommand('startRecording', options);
  1004. }
  1005. /**
  1006. * Stops a recording or streaming session that is in progress.
  1007. *
  1008. * @param {string} mode - `file` or `stream`.
  1009. * @returns {void}
  1010. */
  1011. stopRecording(mode) {
  1012. this.executeCommand('startRecording', mode);
  1013. }
  1014. }