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

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