您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

statistics.js 21KB

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