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

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