Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

statistics.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. import EventEmitter from 'events';
  2. import {
  3. FEEDBACK,
  4. ICE_FAILED
  5. } from '../../service/statistics/AnalyticsEvents';
  6. import analytics from './AnalyticsAdapter';
  7. import CallStats from './CallStats';
  8. import LocalStats from './LocalStatsCollector';
  9. import RTPStats from './RTPStatsCollector';
  10. import RTCBrowserType from '../RTC/RTCBrowserType';
  11. import Settings from '../settings/Settings';
  12. import ScriptUtil from '../util/ScriptUtil';
  13. import JitsiTrackError from '../../JitsiTrackError';
  14. import * as StatisticsEvents from '../../service/statistics/Events';
  15. const logger = require('jitsi-meet-logger').getLogger(__filename);
  16. /**
  17. * Stores all active {@link Statistics} instances.
  18. * @type {Set<Statistics>}
  19. */
  20. let _instances;
  21. /**
  22. * True if callstats API is loaded
  23. */
  24. let isCallstatsLoaded = false;
  25. /**
  26. * Since callstats.io is a third party, we cannot guarantee the quality of their
  27. * service. More specifically, their server may take noticeably long time to
  28. * respond. Consequently, it is in our best interest (in the sense that the
  29. * intergration of callstats.io is pretty important to us but not enough to
  30. * allow it to prevent people from joining a conference) to (1) start
  31. * downloading their API as soon as possible and (2) do the downloading
  32. * asynchronously.
  33. *
  34. * @param {StatisticsOptions} options - Options to use for downloading and
  35. * initializing callstats backend.
  36. */
  37. function loadCallStatsAPI(options) {
  38. if (!isCallstatsLoaded) {
  39. ScriptUtil.loadScript(
  40. options.customScriptUrl
  41. || 'https://api.callstats.io/static/callstats-ws.min.js',
  42. /* async */ true,
  43. /* prepend */ true,
  44. /* relativeURL */ undefined,
  45. /* loadCallback */ () => _initCallStatsBackend(options)
  46. );
  47. isCallstatsLoaded = true;
  48. }
  49. }
  50. /**
  51. * Initializes Callstats backend.
  52. *
  53. * @param {StatisticsOptions} options - The options to use for initializing
  54. * callstats backend.
  55. * @private
  56. */
  57. function _initCallStatsBackend(options) {
  58. if (CallStats.isBackendInitialized()) {
  59. return;
  60. }
  61. const userName = Settings.callStatsUserName;
  62. if (!CallStats.initBackend({
  63. callStatsID: options.callStatsID,
  64. callStatsSecret: options.callStatsSecret,
  65. userName: options.swapUserNameAndAlias
  66. ? options.callStatsAliasName : userName,
  67. aliasName: options.swapUserNameAndAlias
  68. ? userName : options.callStatsAliasName,
  69. applicationName: options.applicationName,
  70. getWiFiStatsMethod: options.getWiFiStatsMethod
  71. })) {
  72. logger.error('CallStats Backend initialization failed bad');
  73. }
  74. }
  75. /**
  76. * callstats strips any additional fields from Error except for "name", "stack",
  77. * "message" and "constraintName". So we need to bundle additional information
  78. * from JitsiTrackError into error passed to callstats to preserve valuable
  79. * information about error.
  80. * @param {JitsiTrackError} error
  81. */
  82. function formatJitsiTrackErrorForCallStats(error) {
  83. const err = new Error();
  84. // Just copy original stack from error
  85. err.stack = error.stack;
  86. // Combine name from error's name plus (possibly) name of original GUM error
  87. err.name = (error.name || 'Unknown error') + (error.gum && error.gum.error
  88. && error.gum.error.name ? ` - ${error.gum.error.name}` : '');
  89. // Put all constraints into this field. For constraint failed errors we will
  90. // still know which exactly constraint failed as it will be a part of
  91. // message.
  92. err.constraintName = error.gum && error.gum.constraints
  93. ? JSON.stringify(error.gum.constraints) : '';
  94. // Just copy error's message.
  95. err.message = error.message;
  96. return err;
  97. }
  98. /**
  99. * Init statistic options
  100. * @param options
  101. */
  102. Statistics.init = function(options) {
  103. Statistics.audioLevelsEnabled = !options.disableAudioLevels;
  104. if (typeof options.audioLevelsInterval === 'number') {
  105. Statistics.audioLevelsInterval = options.audioLevelsInterval;
  106. }
  107. Statistics.disableThirdPartyRequests = options.disableThirdPartyRequests;
  108. };
  109. /**
  110. * The options to configure Statistics.
  111. * @typedef {Object} StatisticsOptions
  112. * @property {string} applicationName - The application name to pass to
  113. * callstats.
  114. * @property {string} callStatsAliasName - The alias name to use when
  115. * initializing callstats.
  116. * @property {string} callStatsConfIDNamespace - A namespace to prepend the
  117. * callstats conference ID with.
  118. * @property {string} callStatsID - Callstats credentials - the id.
  119. * @property {string} callStatsSecret - Callstats credentials - the secret.
  120. * @property {string} customScriptUrl - A custom lib url to use when downloading
  121. * callstats library.
  122. * @property {string} roomName - The room name we are currently in.
  123. * @property {boolean} swapUserNameAndAlias - Whether to swap the places of
  124. * username and alias when initiating callstats.
  125. */
  126. /**
  127. *
  128. * @param xmpp
  129. * @param {StatisticsOptions} options - The options to use creating the
  130. * Statistics.
  131. */
  132. export default function Statistics(xmpp, options) {
  133. /**
  134. * {@link RTPStats} mapped by {@link TraceablePeerConnection.id} which
  135. * collect RTP statistics for each peerconnection.
  136. * @type {Map<string, RTPStats}
  137. */
  138. this.rtpStatsMap = new Map();
  139. this.eventEmitter = new EventEmitter();
  140. this.xmpp = xmpp;
  141. this.options = options || {};
  142. this.callStatsIntegrationEnabled
  143. = this.options.callStatsID && this.options.callStatsSecret
  144. // Even though AppID and AppSecret may be specified, the integration
  145. // of callstats.io may be disabled because of globally-disallowed
  146. // requests to any third parties.
  147. && (Statistics.disableThirdPartyRequests !== true);
  148. if (this.callStatsIntegrationEnabled) {
  149. if (RTCBrowserType.isReactNative()) {
  150. _initCallStatsBackend(this.options);
  151. } else {
  152. loadCallStatsAPI(this.options);
  153. }
  154. if (!this.options.callStatsConfIDNamespace) {
  155. logger.warn('"callStatsConfIDNamespace" is not defined');
  156. }
  157. }
  158. /**
  159. * Stores {@link CallStats} instances for each
  160. * {@link TraceablePeerConnection} (one {@link CallStats} instance serves
  161. * one TPC). The instances are mapped by {@link TraceablePeerConnection.id}.
  162. * @type {Map<number, CallStats>}
  163. */
  164. this.callsStatsInstances = new Map();
  165. Statistics.instances.add(this);
  166. }
  167. Statistics.audioLevelsEnabled = false;
  168. Statistics.audioLevelsInterval = 200;
  169. Statistics.disableThirdPartyRequests = false;
  170. Statistics.analytics = analytics;
  171. Object.defineProperty(Statistics, 'instances', {
  172. /**
  173. * Returns the Set holding all active {@link Statistics} instances. Lazily
  174. * initializes the Set to allow any Set polyfills to be applied.
  175. * @type {Set<Statistics>}
  176. */
  177. get() {
  178. if (!_instances) {
  179. _instances = new Set();
  180. }
  181. return _instances;
  182. }
  183. });
  184. /**
  185. * Starts collecting RTP stats for given peerconnection.
  186. * @param {TraceablePeerConnection} peerconnection
  187. */
  188. Statistics.prototype.startRemoteStats = function(peerconnection) {
  189. this.stopRemoteStats(peerconnection);
  190. try {
  191. const rtpStats
  192. = new RTPStats(
  193. peerconnection,
  194. Statistics.audioLevelsInterval,
  195. 2000,
  196. this.eventEmitter);
  197. rtpStats.start(Statistics.audioLevelsEnabled);
  198. this.rtpStatsMap.set(peerconnection.id, rtpStats);
  199. } catch (e) {
  200. logger.error(`Failed to start collecting remote statistics: ${e}`);
  201. }
  202. };
  203. Statistics.localStats = [];
  204. Statistics.startLocalStats = function(stream, callback) {
  205. if (!Statistics.audioLevelsEnabled) {
  206. return;
  207. }
  208. const localStats = new LocalStats(stream, Statistics.audioLevelsInterval,
  209. callback);
  210. this.localStats.push(localStats);
  211. localStats.start();
  212. };
  213. Statistics.prototype.addAudioLevelListener = function(listener) {
  214. if (!Statistics.audioLevelsEnabled) {
  215. return;
  216. }
  217. this.eventEmitter.on(StatisticsEvents.AUDIO_LEVEL, listener);
  218. };
  219. Statistics.prototype.removeAudioLevelListener = function(listener) {
  220. if (!Statistics.audioLevelsEnabled) {
  221. return;
  222. }
  223. this.eventEmitter.removeListener(StatisticsEvents.AUDIO_LEVEL, listener);
  224. };
  225. Statistics.prototype.addBeforeDisposedListener = function(listener) {
  226. this.eventEmitter.on(StatisticsEvents.BEFORE_DISPOSED, listener);
  227. };
  228. Statistics.prototype.removeBeforeDisposedListener = function(listener) {
  229. this.eventEmitter.removeListener(
  230. StatisticsEvents.BEFORE_DISPOSED, listener);
  231. };
  232. Statistics.prototype.addConnectionStatsListener = function(listener) {
  233. this.eventEmitter.on(StatisticsEvents.CONNECTION_STATS, listener);
  234. };
  235. Statistics.prototype.removeConnectionStatsListener = function(listener) {
  236. this.eventEmitter.removeListener(
  237. StatisticsEvents.CONNECTION_STATS,
  238. listener);
  239. };
  240. Statistics.prototype.addByteSentStatsListener = function(listener) {
  241. this.eventEmitter.on(StatisticsEvents.BYTE_SENT_STATS, listener);
  242. };
  243. Statistics.prototype.removeByteSentStatsListener = function(listener) {
  244. this.eventEmitter.removeListener(StatisticsEvents.BYTE_SENT_STATS,
  245. listener);
  246. };
  247. Statistics.prototype.dispose = function() {
  248. try {
  249. // NOTE Before reading this please see the comment in stopCallStats...
  250. //
  251. // Here we prevent from emitting the event twice in case it will be
  252. // triggered from stopCallStats.
  253. // If the event is triggered from here it means that the logs will not
  254. // be submitted anyway (because there is no CallStats instance), but
  255. // we're doing that for the sake of some kind of consistency.
  256. if (!this.callsStatsInstances.size) {
  257. this.eventEmitter.emit(StatisticsEvents.BEFORE_DISPOSED);
  258. }
  259. for (const callStats of this.callsStatsInstances.values()) {
  260. this.stopCallStats(callStats.tpc);
  261. }
  262. for (const tpcId of this.rtpStatsMap.keys()) {
  263. this._stopRemoteStats(tpcId);
  264. }
  265. if (this.eventEmitter) {
  266. this.eventEmitter.removeAllListeners();
  267. }
  268. } finally {
  269. Statistics.instances.delete(this);
  270. }
  271. };
  272. Statistics.stopLocalStats = function(stream) {
  273. if (!Statistics.audioLevelsEnabled) {
  274. return;
  275. }
  276. for (let i = 0; i < Statistics.localStats.length; i++) {
  277. if (Statistics.localStats[i].stream === stream) {
  278. const localStats = Statistics.localStats.splice(i, 1);
  279. localStats[0].stop();
  280. break;
  281. }
  282. }
  283. };
  284. /**
  285. * Stops remote RTP stats for given peerconnection ID.
  286. * @param {string} tpcId {@link TraceablePeerConnection.id}
  287. * @private
  288. */
  289. Statistics.prototype._stopRemoteStats = function(tpcId) {
  290. const rtpStats = this.rtpStatsMap.get(tpcId);
  291. if (rtpStats) {
  292. rtpStats.stop();
  293. this.rtpStatsMap.delete(tpcId);
  294. }
  295. };
  296. /**
  297. * Stops collecting RTP stats for given peerconnection
  298. * @param {TraceablePeerConnection} tpc
  299. */
  300. Statistics.prototype.stopRemoteStats = function(tpc) {
  301. this._stopRemoteStats(tpc.id);
  302. };
  303. // CALSTATS METHODS
  304. /**
  305. * Initializes the callstats.io API.
  306. * @param {TraceablePeerConnection} tpc the {@link TraceablePeerConnection}
  307. * instance for which CalStats will be started.
  308. * @param {string} remoteUserID
  309. */
  310. Statistics.prototype.startCallStats = function(tpc, remoteUserID) {
  311. if (!this.callStatsIntegrationEnabled) {
  312. return;
  313. } else if (this.callsStatsInstances.has(tpc.id)) {
  314. logger.error('CallStats instance for ${tpc} exists already');
  315. return;
  316. }
  317. logger.info(`Starting CallStats for ${tpc}...`);
  318. const newInstance
  319. = new CallStats(
  320. tpc,
  321. {
  322. confID: this._getCallStatsConfID(),
  323. remoteUserID
  324. });
  325. this.callsStatsInstances.set(tpc.id, newInstance);
  326. };
  327. /**
  328. * Obtains the list of *all* {@link CallStats} instances collected from every
  329. * valid {@link Statistics} instance.
  330. * @return {Set<CallStats>}
  331. * @private
  332. */
  333. Statistics._getAllCallStatsInstances = function() {
  334. const csInstances = new Set();
  335. for (const statistics of Statistics.instances) {
  336. for (const cs of statistics.callsStatsInstances.values()) {
  337. csInstances.add(cs);
  338. }
  339. }
  340. return csInstances;
  341. };
  342. /**
  343. * Constructs the CallStats conference ID based on the options currently
  344. * configured in this instance.
  345. * @return {string}
  346. * @private
  347. */
  348. Statistics.prototype._getCallStatsConfID = function() {
  349. // The conference ID is case sensitive!!!
  350. return this.options.callStatsConfIDNamespace
  351. ? `${this.options.callStatsConfIDNamespace}/${this.options.roomName}`
  352. : this.options.roomName;
  353. };
  354. /**
  355. * Removes the callstats.io instances.
  356. */
  357. Statistics.prototype.stopCallStats = function(tpc) {
  358. const callStatsInstance = this.callsStatsInstances.get(tpc.id);
  359. if (callStatsInstance) {
  360. // FIXME the original purpose of adding BEFORE_DISPOSED event was to be
  361. // able to submit the last log batch from jitsi-meet to CallStats. After
  362. // recent changes we dispose the CallStats earlier
  363. // (before Statistics.dispose), so we need to emit this event here to
  364. // give this last chance for final log batch submission.
  365. //
  366. // Eventually there should be a separate module called "log storage"
  367. // which should emit proper events when it's underlying
  368. // CallStats instance is going away.
  369. if (this.callsStatsInstances.size === 1) {
  370. this.eventEmitter.emit(StatisticsEvents.BEFORE_DISPOSED);
  371. }
  372. this.callsStatsInstances.delete(tpc.id);
  373. // The fabric needs to be terminated when being stopped
  374. callStatsInstance.sendTerminateEvent();
  375. }
  376. };
  377. /**
  378. * Returns true if the callstats integration is enabled, otherwise returns
  379. * false.
  380. *
  381. * @returns true if the callstats integration is enabled, otherwise returns
  382. * false.
  383. */
  384. Statistics.prototype.isCallstatsEnabled = function() {
  385. return this.callStatsIntegrationEnabled;
  386. };
  387. /**
  388. * Logs either resume or hold event for the given peer connection.
  389. * @param {TraceablePeerConnection} tpc the connection for which event will be
  390. * reported
  391. * @param {boolean} isResume true for resume or false for hold
  392. */
  393. Statistics.prototype.sendConnectionResumeOrHoldEvent = function(tpc, isResume) {
  394. const instance = this.callsStatsInstances.get(tpc.id);
  395. if (instance) {
  396. instance.sendResumeOrHoldEvent(isResume);
  397. }
  398. };
  399. /**
  400. * Notifies CallStats and analytics (if present) for ice connection failed
  401. * @param {TraceablePeerConnection} tpc connection on which failure occurred.
  402. */
  403. Statistics.prototype.sendIceConnectionFailedEvent = function(tpc) {
  404. const instance = this.callsStatsInstances.get(tpc.id);
  405. if (instance) {
  406. instance.sendIceConnectionFailedEvent();
  407. }
  408. Statistics.analytics.sendEvent(ICE_FAILED);
  409. };
  410. /**
  411. * Notifies CallStats for mute events
  412. * @param {TraceablePeerConnection} tpc connection on which failure occurred.
  413. * @param {boolean} muted true for muted and false for not muted
  414. * @param {String} type "audio"/"video"
  415. */
  416. Statistics.prototype.sendMuteEvent = function(tpc, muted, type) {
  417. const instance = tpc && this.callsStatsInstances.get(tpc.id);
  418. CallStats.sendMuteEvent(muted, type, instance);
  419. };
  420. /**
  421. * Notifies CallStats for screen sharing events
  422. * @param start {boolean} true for starting screen sharing and
  423. * false for not stopping
  424. * @param {string|null} ssrc - optional ssrc value, used only when
  425. * starting screen sharing.
  426. */
  427. Statistics.prototype.sendScreenSharingEvent
  428. = function(start, ssrc) {
  429. for (const cs of this.callsStatsInstances.values()) {
  430. cs.sendScreenSharingEvent(start, ssrc);
  431. }
  432. };
  433. /**
  434. * Notifies the statistics module that we are now the dominant speaker of the
  435. * conference.
  436. */
  437. Statistics.prototype.sendDominantSpeakerEvent = function() {
  438. for (const cs of this.callsStatsInstances.values()) {
  439. cs.sendDominantSpeakerEvent();
  440. }
  441. };
  442. /**
  443. * Notifies about active device.
  444. * @param {{deviceList: {String:String}}} devicesData - list of devices with
  445. * their data
  446. */
  447. Statistics.sendActiveDeviceListEvent = function(devicesData) {
  448. const globalSet = Statistics._getAllCallStatsInstances();
  449. if (globalSet.size) {
  450. for (const cs of globalSet) {
  451. CallStats.sendActiveDeviceListEvent(devicesData, cs);
  452. }
  453. } else {
  454. CallStats.sendActiveDeviceListEvent(devicesData, null);
  455. }
  456. };
  457. /* eslint-disable max-params */
  458. /**
  459. * Lets the underlying statistics module know where is given SSRC rendered by
  460. * providing renderer tag ID.
  461. * @param {TraceablePeerConnection} tpc the connection to which the stream
  462. * belongs to
  463. * @param {number} ssrc the SSRC of the stream
  464. * @param {boolean} isLocal
  465. * @param {string} userId
  466. * @param {string} usageLabel meaningful usage label of this stream like
  467. * 'microphone', 'camera' or 'screen'.
  468. * @param {string} containerId the id of media 'audio' or 'video' tag which
  469. * renders the stream.
  470. */
  471. Statistics.prototype.associateStreamWithVideoTag = function(
  472. tpc,
  473. ssrc,
  474. isLocal,
  475. userId,
  476. usageLabel,
  477. containerId) {
  478. const instance = this.callsStatsInstances.get(tpc.id);
  479. if (instance) {
  480. instance.associateStreamWithVideoTag(
  481. ssrc,
  482. isLocal,
  483. userId,
  484. usageLabel,
  485. containerId);
  486. }
  487. };
  488. /* eslint-enable max-params */
  489. /**
  490. * Notifies CallStats that getUserMedia failed.
  491. *
  492. * @param {Error} e error to send
  493. */
  494. Statistics.sendGetUserMediaFailed = function(e) {
  495. const error
  496. = e instanceof JitsiTrackError
  497. ? formatJitsiTrackErrorForCallStats(e) : e;
  498. const globalSet = Statistics._getAllCallStatsInstances();
  499. if (globalSet.size) {
  500. for (const cs of globalSet) {
  501. CallStats.sendGetUserMediaFailed(error, cs);
  502. }
  503. } else {
  504. CallStats.sendGetUserMediaFailed(error, null);
  505. }
  506. };
  507. /**
  508. * Notifies CallStats that peer connection failed to create offer.
  509. *
  510. * @param {Error} e error to send
  511. * @param {TraceablePeerConnection} tpc connection on which failure occurred.
  512. */
  513. Statistics.prototype.sendCreateOfferFailed = function(e, tpc) {
  514. const instance = this.callsStatsInstances.get(tpc.id);
  515. if (instance) {
  516. instance.sendCreateOfferFailed(e);
  517. }
  518. };
  519. /**
  520. * Notifies CallStats that peer connection failed to create answer.
  521. *
  522. * @param {Error} e error to send
  523. * @param {TraceablePeerConnection} tpc connection on which failure occured.
  524. */
  525. Statistics.prototype.sendCreateAnswerFailed = function(e, tpc) {
  526. const instance = this.callsStatsInstances.get(tpc.id);
  527. if (instance) {
  528. instance.sendCreateAnswerFailed(e);
  529. }
  530. };
  531. /**
  532. * Notifies CallStats that peer connection failed to set local description.
  533. *
  534. * @param {Error} e error to send
  535. * @param {TraceablePeerConnection} tpc connection on which failure occurred.
  536. */
  537. Statistics.prototype.sendSetLocalDescFailed = function(e, tpc) {
  538. const instance = this.callsStatsInstances.get(tpc.id);
  539. if (instance) {
  540. instance.sendSetLocalDescFailed(e);
  541. }
  542. };
  543. /**
  544. * Notifies CallStats that peer connection failed to set remote description.
  545. *
  546. * @param {Error} e error to send
  547. * @param {TraceablePeerConnection} tpc connection on which failure occurred.
  548. */
  549. Statistics.prototype.sendSetRemoteDescFailed = function(e, tpc) {
  550. const instance = this.callsStatsInstances.get(tpc.id);
  551. if (instance) {
  552. instance.sendSetRemoteDescFailed(e);
  553. }
  554. };
  555. /**
  556. * Notifies CallStats that peer connection failed to add ICE candidate.
  557. *
  558. * @param {Error} e error to send
  559. * @param {TraceablePeerConnection} tpc connection on which failure occurred.
  560. */
  561. Statistics.prototype.sendAddIceCandidateFailed = function(e, tpc) {
  562. const instance = this.callsStatsInstances.get(tpc.id);
  563. if (instance) {
  564. instance.sendAddIceCandidateFailed(e);
  565. }
  566. };
  567. /**
  568. * Adds to CallStats an application log.
  569. *
  570. * @param {String} m a log message to send or an {Error} object to be reported
  571. */
  572. Statistics.sendLog = function(m) {
  573. const globalSubSet = new Set();
  574. // FIXME we don't want to duplicate logs over P2P instance, but
  575. // here we should go over instances and call this method for each
  576. // unique conference ID rather than selecting the first one.
  577. // We don't have such use case though, so leaving as is for now.
  578. for (const stats of Statistics.instances) {
  579. if (stats.callsStatsInstances.size) {
  580. globalSubSet.add(stats.callsStatsInstances.values().next().value);
  581. }
  582. }
  583. if (globalSubSet.size) {
  584. for (const csPerStats of globalSubSet) {
  585. CallStats.sendApplicationLog(m, csPerStats);
  586. }
  587. } else {
  588. CallStats.sendApplicationLog(m, null);
  589. }
  590. };
  591. /**
  592. * Sends the given feedback through CallStats.
  593. *
  594. * @param overall an integer between 1 and 5 indicating the user feedback
  595. * @param detailed detailed feedback from the user. Not yet used
  596. */
  597. Statistics.prototype.sendFeedback = function(overall, detailed) {
  598. CallStats.sendFeedback(this._getCallStatsConfID(), overall, detailed);
  599. Statistics.analytics.sendEvent(
  600. FEEDBACK,
  601. {
  602. value: overall,
  603. detailed
  604. });
  605. };
  606. Statistics.LOCAL_JID = require('../../service/statistics/constants').LOCAL_JID;
  607. /**
  608. * Reports global error to CallStats.
  609. *
  610. * @param {Error} error
  611. */
  612. Statistics.reportGlobalError = function(error) {
  613. if (error instanceof JitsiTrackError && error.gum) {
  614. Statistics.sendGetUserMediaFailed(error);
  615. } else {
  616. Statistics.sendLog(error);
  617. }
  618. };
  619. /**
  620. * Sends event to analytics and callstats.
  621. * @param {string} eventName the event name.
  622. * @param {Object} data the data to be sent.
  623. */
  624. Statistics.sendEventToAll = function(eventName, data) {
  625. this.analytics.sendEvent(eventName, data);
  626. Statistics.sendLog(
  627. JSON.stringify(
  628. {
  629. name: eventName,
  630. data
  631. }));
  632. };