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.

statistics.js 22KB

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