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

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