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

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