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.

CallStats.js 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /* global callstats */
  2. import RTCBrowserType from '../RTC/RTCBrowserType';
  3. import GlobalOnErrorHandler from '../util/GlobalOnErrorHandler';
  4. const logger = require('jitsi-meet-logger').getLogger(__filename);
  5. /**
  6. * We define enumeration of wrtcFuncNames as we need them before
  7. * callstats is initialized to queue events.
  8. * @const
  9. * @see http://www.callstats.io/api/#enumeration-of-wrtcfuncnames
  10. */
  11. const wrtcFuncNames = {
  12. createOffer: 'createOffer',
  13. createAnswer: 'createAnswer',
  14. setLocalDescription: 'setLocalDescription',
  15. setRemoteDescription: 'setRemoteDescription',
  16. addIceCandidate: 'addIceCandidate',
  17. getUserMedia: 'getUserMedia',
  18. iceConnectionFailure: 'iceConnectionFailure',
  19. signalingError: 'signalingError',
  20. applicationLog: 'applicationLog'
  21. };
  22. /**
  23. * We define enumeration of fabricEvent as we need them before
  24. * callstats is initialized to queue events.
  25. * @const
  26. * @see http://www.callstats.io/api/#enumeration-of-fabricevent
  27. */
  28. const fabricEvent = {
  29. fabricHold: 'fabricHold',
  30. fabricResume: 'fabricResume',
  31. audioMute: 'audioMute',
  32. audioUnmute: 'audioUnmute',
  33. videoPause: 'videoPause',
  34. videoResume: 'videoResume',
  35. fabricUsageEvent: 'fabricUsageEvent',
  36. fabricStats: 'fabricStats',
  37. fabricTerminated: 'fabricTerminated',
  38. screenShareStart: 'screenShareStart',
  39. screenShareStop: 'screenShareStop',
  40. dominantSpeaker: 'dominantSpeaker',
  41. activeDeviceList: 'activeDeviceList'
  42. };
  43. /**
  44. * The user id to report to callstats as destination.
  45. * @type {string}
  46. */
  47. const DEFAULT_REMOTE_USER = 'jitsi';
  48. /**
  49. * Type of pending reports, can be event or an error.
  50. * @type {{ERROR: string, EVENT: string}}
  51. */
  52. const reportType = {
  53. ERROR: 'error',
  54. EVENT: 'event',
  55. MST_WITH_USERID: 'mstWithUserID'
  56. };
  57. /**
  58. * Set of currently existing {@link CallStats} instances.
  59. * @type {Set<CallStats>}
  60. */
  61. let _fabrics;
  62. /**
  63. * An instance of this class is a wrapper for the CallStats API fabric. A fabric
  64. * reports one peer connection the the CallStats backend and is allocated with
  65. * {@link callstats.addNewFabric}. It has a bunch of instance methods for
  66. * reporting various events. A fabric is considered disposed when
  67. * {@link CallStats.sendTerminateEvent} is executed.
  68. *
  69. * Currently only one backend instance can be created ever and it's done using
  70. * {@link CallStats.initBackend}. At the time of this writing there is no way to
  71. * explicitly shutdown the backend, but it's supposed to close it's connection
  72. * automatically, after all fabrics have been terminated.
  73. */
  74. export default class CallStats {
  75. /**
  76. * A callback passed to {@link callstats.addNewFabric}.
  77. * @param {string} error 'success' means ok
  78. * @param {string} msg some more details
  79. * @private
  80. */
  81. static _addNewFabricCallback(error, msg) {
  82. if (CallStats.backend && error !== 'success') {
  83. logger.error(`Monitoring status: ${error} msg: ${msg}`);
  84. }
  85. }
  86. /**
  87. * Callback passed to {@link callstats.initialize} (backend initialization)
  88. * @param {string} error 'success' means ok
  89. * @param {String} msg
  90. * @private
  91. */
  92. static _initCallback(error, msg) {
  93. logger.log(`CallStats Status: err=${error} msg=${msg}`);
  94. // there is no lib, nothing to report to
  95. if (error !== 'success') {
  96. return;
  97. }
  98. // I hate that
  99. let atLeastOneFabric = false;
  100. let defaultInstance = null;
  101. for (const callStatsInstance of CallStats.fabrics.values()) {
  102. if (!callStatsInstance.hasFabric) {
  103. logger.debug('addNewFabric - initCallback');
  104. if (callStatsInstance._addNewFabric()) {
  105. atLeastOneFabric = true;
  106. if (!defaultInstance) {
  107. defaultInstance = callStatsInstance;
  108. }
  109. }
  110. }
  111. }
  112. if (!atLeastOneFabric) {
  113. return;
  114. }
  115. CallStats.initialized = true;
  116. // There is no conference ID nor a PeerConnection available when some of
  117. // the events are scheduled on the reportsQueue, so those will be
  118. // reported on the first initialized fabric.
  119. const defaultConfID = defaultInstance.confID;
  120. const defaultPC = defaultInstance.peerconnection;
  121. // notify callstats about failures if there were any
  122. for (const report of CallStats.reportsQueue) {
  123. if (report.type === reportType.ERROR) {
  124. const errorData = report.data;
  125. CallStats._reportError(
  126. defaultInstance,
  127. errorData.type,
  128. errorData.error,
  129. errorData.pc || defaultPC);
  130. } else if (report.type === reportType.EVENT) {
  131. // if we have and event to report and we failed to add
  132. // fabric this event will not be reported anyway, returning
  133. // an error
  134. const eventData = report.data;
  135. CallStats.backend.sendFabricEvent(
  136. report.pc || defaultPC,
  137. eventData.event,
  138. defaultConfID,
  139. eventData.eventData);
  140. } else if (report.type === reportType.MST_WITH_USERID) {
  141. const data = report.data;
  142. CallStats.backend.associateMstWithUserID(
  143. report.pc || defaultPC,
  144. data.callStatsId,
  145. defaultConfID,
  146. data.ssrc,
  147. data.usageLabel,
  148. data.containerId
  149. );
  150. }
  151. }
  152. CallStats.reportsQueue.length = 0;
  153. }
  154. /* eslint-disable max-params */
  155. /**
  156. * Reports an error to callstats.
  157. *
  158. * @param {CallStats} [cs]
  159. * @param type the type of the error, which will be one of the wrtcFuncNames
  160. * @param error the error
  161. * @param pc the peerconnection
  162. * @private
  163. */
  164. static _reportError(cs, type, error, pc) {
  165. let _error = error;
  166. if (!_error) {
  167. logger.warn('No error is passed!');
  168. _error = new Error('Unknown error');
  169. }
  170. if (CallStats.initialized && cs) {
  171. CallStats.backend.reportError(pc, cs.confID, type, _error);
  172. } else {
  173. CallStats.reportsQueue.push({
  174. type: reportType.ERROR,
  175. data: {
  176. error: _error,
  177. pc,
  178. type
  179. }
  180. });
  181. }
  182. // else just ignore it
  183. }
  184. /* eslint-enable max-params */
  185. /**
  186. * Reports an error to callstats.
  187. *
  188. * @param {CallStats} cs
  189. * @param event the type of the event, which will be one of the fabricEvent
  190. * @param eventData additional data to pass to event
  191. * @private
  192. */
  193. static _reportEvent(cs, event, eventData) {
  194. const pc = cs && cs.peerconnection;
  195. const confID = cs && cs.confID;
  196. if (CallStats.initialized && cs) {
  197. CallStats.backend.sendFabricEvent(pc, event, confID, eventData);
  198. } else {
  199. CallStats.reportsQueue.push({
  200. confID,
  201. pc,
  202. type: reportType.EVENT,
  203. data: { event,
  204. eventData }
  205. });
  206. }
  207. }
  208. /**
  209. * Wraps some of the CallStats API method and logs their calls with
  210. * arguments on the debug logging level. Also wraps some of the backend
  211. * methods execution into try catch blocks to not crash the app in case
  212. * there is a problem with the backend itself.
  213. * @param {callstats} theBackend
  214. * @private
  215. */
  216. static _traceAndCatchBackendCalls(theBackend) {
  217. const tryCatchMethods = [
  218. 'associateMstWithUserID',
  219. 'sendFabricEvent',
  220. 'sendUserFeedback'
  221. // 'reportError', - this one needs special handling - see code below
  222. ];
  223. for (const methodName of tryCatchMethods) {
  224. const originalMethod = theBackend[methodName];
  225. theBackend[methodName] = function(...theArguments) {
  226. try {
  227. return originalMethod.apply(theBackend, theArguments);
  228. } catch (e) {
  229. GlobalOnErrorHandler.callErrorHandler(e);
  230. }
  231. };
  232. }
  233. const debugMethods = [
  234. 'associateMstWithUserID',
  235. 'sendFabricEvent',
  236. 'sendUserFeedback'
  237. // 'reportError', - this one needs special handling - see code below
  238. ];
  239. for (const methodName of debugMethods) {
  240. const originalMethod = theBackend[methodName];
  241. theBackend[methodName] = function(...theArguments) {
  242. logger.debug(methodName, theArguments);
  243. originalMethod.apply(theBackend, theArguments);
  244. };
  245. }
  246. const originalReportError = theBackend.reportError;
  247. /* eslint-disable max-params */
  248. theBackend.reportError
  249. = function(pc, cs, type, ...args) {
  250. // Logs from the logger are submitted on the applicationLog event
  251. // "type". Logging the arguments on the logger will create endless
  252. // loop, because it will put all the logs to the logger queue again.
  253. if (type === wrtcFuncNames.applicationLog) {
  254. // NOTE otherArguments are not logged to the console on purpose
  255. // to not log the whole log batch
  256. // FIXME check the current logging level (currently not exposed
  257. // by the logger implementation)
  258. // NOTE it is not safe to log whole objects on react-native as
  259. // those contain too many circular references and may crash
  260. // the app.
  261. if (!RTCBrowserType.isReactNative()) {
  262. console && console.debug('reportError', pc, cs, type);
  263. }
  264. } else {
  265. logger.debug('reportError', pc, cs, type, ...args);
  266. }
  267. try {
  268. originalReportError.call(theBackend, pc, cs, type, ...args);
  269. } catch (exception) {
  270. if (type === wrtcFuncNames.applicationLog) {
  271. console && console.error('reportError', exception);
  272. } else {
  273. GlobalOnErrorHandler.callErrorHandler(exception);
  274. }
  275. }
  276. };
  277. /* eslint-enable max-params */
  278. }
  279. /**
  280. * Returns the Set with the currently existing {@link CallStats} instances.
  281. * Lazily initializes the Set to allow any Set polyfills to be applied.
  282. * @type {Set<CallStats>}
  283. */
  284. static get fabrics() {
  285. if (!_fabrics) {
  286. _fabrics = new Set();
  287. }
  288. return _fabrics;
  289. }
  290. /**
  291. * Initializes the CallStats backend. Should be called only if
  292. * {@link CallStats.isBackendInitialized} returns <tt>false</tt>.
  293. * @param {object} options
  294. * @param {String} options.callStatsID CallStats credentials - ID
  295. * @param {String} options.callStatsSecret CallStats credentials - secret
  296. * @param {string} options.aliasName the <tt>aliasName</tt> part of
  297. * the <tt>userID</tt> aka endpoint ID, see CallStats docs for more info.
  298. * @param {string} options.userName the <tt>userName</tt> part of
  299. * the <tt>userID</tt> aka display name, see CallStats docs for more info.
  300. *
  301. */
  302. static initBackend(options) {
  303. if (CallStats.backend) {
  304. throw new Error('CallStats backend has been initialized already!');
  305. }
  306. try {
  307. // In react-native we need to import the callstats module, but
  308. // imports are only allowed at top-level, so we must use require
  309. // here. Sigh.
  310. const CallStatsBackend
  311. = RTCBrowserType.isReactNative()
  312. ? require('react-native-callstats/callstats')
  313. : callstats;
  314. CallStats.backend = new CallStatsBackend();
  315. CallStats._traceAndCatchBackendCalls(CallStats.backend);
  316. CallStats.userID = {
  317. aliasName: options.aliasName,
  318. userName: options.userName
  319. };
  320. CallStats.callStatsID = options.callStatsID;
  321. CallStats.callStatsSecret = options.callStatsSecret;
  322. // userID is generated or given by the origin server
  323. CallStats.backend.initialize(
  324. CallStats.callStatsID,
  325. CallStats.callStatsSecret,
  326. CallStats.userID,
  327. CallStats._initCallback);
  328. return true;
  329. } catch (e) {
  330. // The callstats.io API failed to initialize (e.g. because its
  331. // download did not succeed in general or on time). Further attempts
  332. // to utilize it cannot possibly succeed.
  333. GlobalOnErrorHandler.callErrorHandler(e);
  334. CallStats.backend = null;
  335. logger.error(e);
  336. return false;
  337. }
  338. }
  339. /**
  340. * Checks if the CallStats backend has been created. It does not mean that
  341. * it has been initialized, but only that the API instance has been
  342. * allocated successfully.
  343. * @return {boolean} <tt>true</tt> if backend exists or <tt>false</tt>
  344. * otherwise
  345. */
  346. static isBackendInitialized() {
  347. return Boolean(CallStats.backend);
  348. }
  349. /**
  350. * Notifies CallStats about active device.
  351. * @param {{deviceList: {String:String}}} devicesData list of devices with
  352. * their data
  353. * @param {CallStats} cs callstats instance related to the event
  354. */
  355. static sendActiveDeviceListEvent(devicesData, cs) {
  356. CallStats._reportEvent(cs, fabricEvent.activeDeviceList, devicesData);
  357. }
  358. /**
  359. * Notifies CallStats that there is a log we want to report.
  360. *
  361. * @param {Error} e error to send or {String} message
  362. * @param {CallStats} cs callstats instance related to the error (optional)
  363. */
  364. static sendApplicationLog(e, cs) {
  365. try {
  366. CallStats._reportError(
  367. cs,
  368. wrtcFuncNames.applicationLog,
  369. e,
  370. cs && cs.peerconnection);
  371. } catch (error) {
  372. // If sendApplicationLog fails it should not be printed to
  373. // the logger, because it will try to push the logs again
  374. // (through sendApplicationLog) and an endless loop is created.
  375. if (console && (typeof console.error === 'function')) {
  376. // FIXME send analytics event as well
  377. console.error('sendApplicationLog failed', error);
  378. }
  379. }
  380. }
  381. /**
  382. * Sends the given feedback through CallStats.
  383. *
  384. * @param {string} conferenceID the conference ID for which the feedback
  385. * will be reported.
  386. * @param overallFeedback an integer between 1 and 5 indicating the
  387. * user feedback
  388. * @param detailedFeedback detailed feedback from the user. Not yet used
  389. */
  390. static sendFeedback(conferenceID, overallFeedback, detailedFeedback) {
  391. if (CallStats.backend) {
  392. CallStats.backend.sendUserFeedback(
  393. conferenceID, {
  394. userID: CallStats.userID,
  395. overall: overallFeedback,
  396. comment: detailedFeedback
  397. });
  398. } else {
  399. logger.error('Failed to submit feedback to CallStats - no backend');
  400. }
  401. }
  402. /**
  403. * Notifies CallStats that getUserMedia failed.
  404. *
  405. * @param {Error} e error to send
  406. * @param {CallStats} cs callstats instance related to the error (optional)
  407. */
  408. static sendGetUserMediaFailed(e, cs) {
  409. CallStats._reportError(cs, wrtcFuncNames.getUserMedia, e, null);
  410. }
  411. /**
  412. * Notifies CallStats for mute events
  413. * @param mute {boolean} true for muted and false for not muted
  414. * @param type {String} "audio"/"video"
  415. * @param {CallStats} cs callstats instance related to the event
  416. */
  417. static sendMuteEvent(mute, type, cs) {
  418. let event;
  419. if (type === 'video') {
  420. event = mute ? fabricEvent.videoPause : fabricEvent.videoResume;
  421. } else {
  422. event = mute ? fabricEvent.audioMute : fabricEvent.audioUnmute;
  423. }
  424. CallStats._reportEvent(cs, event);
  425. }
  426. /**
  427. * Creates new CallStats instance that handles all callstats API calls for
  428. * given {@link TraceablePeerConnection}. Each instance is meant to handle
  429. * one CallStats fabric added with 'addFabric' API method for the
  430. * {@link TraceablePeerConnection} instance passed in the constructor.
  431. * @param {TraceablePeerConnection} tpc
  432. * @param {Object} options
  433. * @param {string} options.confID the conference ID that wil be used to
  434. * report the session.
  435. * @param {string} [options.remoteUserID='jitsi'] the remote user ID to
  436. * which given <tt>tpc</tt> is connected.
  437. */
  438. constructor(tpc, options) {
  439. if (!CallStats.backend) {
  440. throw new Error('CallStats backend not intiialized!');
  441. }
  442. this.confID = options.confID;
  443. this.tpc = tpc;
  444. this.peerconnection = tpc.peerconnection;
  445. this.remoteUserID = options.remoteUserID || DEFAULT_REMOTE_USER;
  446. this.hasFabric = false;
  447. CallStats.fabrics.add(this);
  448. if (CallStats.initialized) {
  449. this._addNewFabric();
  450. }
  451. }
  452. /**
  453. * Initializes CallStats fabric by calling "addNewFabric" for
  454. * the peer connection associated with this instance.
  455. * @return {boolean} true if the call was successful or false otherwise.
  456. */
  457. _addNewFabric() {
  458. logger.info('addNewFabric', this.remoteUserID);
  459. try {
  460. const ret
  461. = CallStats.backend.addNewFabric(
  462. this.peerconnection,
  463. this.remoteUserID,
  464. CallStats.backend.fabricUsage.multiplex,
  465. this.confID,
  466. CallStats._addNewFabricCallback);
  467. this.hasFabric = true;
  468. const success = ret.status === 'success';
  469. if (!success) {
  470. logger.error('callstats fabric not initilized', ret.message);
  471. }
  472. return success;
  473. } catch (error) {
  474. GlobalOnErrorHandler.callErrorHandler(error);
  475. return false;
  476. }
  477. }
  478. /* eslint-disable max-params */
  479. /**
  480. * Lets CallStats module know where is given SSRC rendered by providing
  481. * renderer tag ID.
  482. * If the lib is not initialized yet queue the call for later, when it's
  483. * ready.
  484. * @param {number} ssrc the SSRC of the stream
  485. * @param {boolean} isLocal indicates whether this the stream is local
  486. * @param {string|null} streamEndpointId if the stream is not local the it
  487. * needs to contain the stream owner's ID
  488. * @param {string} usageLabel meaningful usage label of this stream like
  489. * 'microphone', 'camera' or 'screen'.
  490. * @param {string} containerId the id of media 'audio' or 'video' tag which
  491. * renders the stream.
  492. */
  493. associateStreamWithVideoTag(
  494. ssrc,
  495. isLocal,
  496. streamEndpointId,
  497. usageLabel,
  498. containerId) {
  499. if (!CallStats.backend) {
  500. return;
  501. }
  502. const callStatsId = isLocal ? CallStats.userID : streamEndpointId;
  503. if (CallStats.initialized) {
  504. CallStats.backend.associateMstWithUserID(
  505. this.peerconnection,
  506. callStatsId,
  507. this.confID,
  508. ssrc,
  509. usageLabel,
  510. containerId);
  511. } else {
  512. CallStats.reportsQueue.push({
  513. type: reportType.MST_WITH_USERID,
  514. pc: this.peerconnection,
  515. data: {
  516. callStatsId,
  517. containerId,
  518. ssrc,
  519. usageLabel
  520. }
  521. });
  522. }
  523. }
  524. /* eslint-enable max-params */
  525. /**
  526. * Notifies CallStats that we are the new dominant speaker in the
  527. * conference.
  528. */
  529. sendDominantSpeakerEvent() {
  530. CallStats._reportEvent(this, fabricEvent.dominantSpeaker);
  531. }
  532. /**
  533. * Notifies CallStats that the fabric for the underlying peerconnection was
  534. * closed and no evens should be reported, after this call.
  535. */
  536. sendTerminateEvent() {
  537. if (CallStats.initialized) {
  538. CallStats.backend.sendFabricEvent(
  539. this.peerconnection,
  540. CallStats.backend.fabricEvent.fabricTerminated,
  541. this.confID);
  542. }
  543. CallStats.fabrics.delete(this);
  544. }
  545. /**
  546. * Notifies CallStats for ice connection failed
  547. */
  548. sendIceConnectionFailedEvent() {
  549. CallStats._reportError(
  550. this,
  551. wrtcFuncNames.iceConnectionFailure,
  552. null,
  553. this.peerconnection);
  554. }
  555. /**
  556. * Notifies CallStats that peer connection failed to create offer.
  557. *
  558. * @param {Error} e error to send
  559. */
  560. sendCreateOfferFailed(e) {
  561. CallStats._reportError(
  562. this, wrtcFuncNames.createOffer, e, this.peerconnection);
  563. }
  564. /**
  565. * Notifies CallStats that peer connection failed to create answer.
  566. *
  567. * @param {Error} e error to send
  568. */
  569. sendCreateAnswerFailed(e) {
  570. CallStats._reportError(
  571. this, wrtcFuncNames.createAnswer, e, this.peerconnection);
  572. }
  573. /**
  574. * Sends either resume or hold event for the fabric associated with
  575. * the underlying peerconnection.
  576. * @param {boolean} isResume true to resume or false to hold
  577. */
  578. sendResumeOrHoldEvent(isResume) {
  579. CallStats._reportEvent(
  580. this,
  581. isResume ? fabricEvent.fabricResume : fabricEvent.fabricHold);
  582. }
  583. /**
  584. * Notifies CallStats for screen sharing events
  585. * @param {boolean} start true for starting screen sharing and
  586. * false for not stopping
  587. */
  588. sendScreenSharingEvent(start) {
  589. CallStats._reportEvent(
  590. this,
  591. start ? fabricEvent.screenShareStart : fabricEvent.screenShareStop);
  592. }
  593. /**
  594. * Notifies CallStats that peer connection failed to set local description.
  595. *
  596. * @param {Error} e error to send
  597. */
  598. sendSetLocalDescFailed(e) {
  599. CallStats._reportError(
  600. this, wrtcFuncNames.setLocalDescription, e, this.peerconnection);
  601. }
  602. /**
  603. * Notifies CallStats that peer connection failed to set remote description.
  604. *
  605. * @param {Error} e error to send
  606. */
  607. sendSetRemoteDescFailed(e) {
  608. CallStats._reportError(
  609. this, wrtcFuncNames.setRemoteDescription, e, this.peerconnection);
  610. }
  611. /**
  612. * Notifies CallStats that peer connection failed to add ICE candidate.
  613. *
  614. * @param {Error} e error to send
  615. */
  616. sendAddIceCandidateFailed(e) {
  617. CallStats._reportError(
  618. this, wrtcFuncNames.addIceCandidate, e, this.peerconnection);
  619. }
  620. }
  621. /**
  622. * The CallStats API backend instance
  623. * @type {callstats}
  624. */
  625. CallStats.backend = null;
  626. // some errors/events may happen before CallStats init
  627. // in this case we accumulate them in this array
  628. // and send them to callstats on init
  629. CallStats.reportsQueue = [];
  630. /**
  631. * Whether the library was successfully initialized using its initialize method.
  632. * And whether we had successfully called addNewFabric at least once.
  633. * @type {boolean}
  634. */
  635. CallStats.initialized = false;
  636. /**
  637. * Part of the CallStats credentials - application ID
  638. * @type {string}
  639. */
  640. CallStats.callStatsID = null;
  641. /**
  642. * Part of the CallStats credentials - application secret
  643. * @type {string}
  644. */
  645. CallStats.callStatsSecret = null;
  646. /**
  647. * Local CallStats user ID structure. Can be set only once when
  648. * {@link backend} is initialized, so it's static for the time being.
  649. * See CallStats API for more info:
  650. * https://www.callstats.io/api/#userid
  651. * @type {object}
  652. */
  653. CallStats.userID = null;