You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

external_api.js 36KB

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