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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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 = function(pc, cs, type, ...args) {
  249. // Logs from the logger are submitted on the applicationLog event
  250. // "type". Logging the arguments on the logger will create endless
  251. // loop, because it will put all the logs to the logger queue again.
  252. if (type === wrtcFuncNames.applicationLog) {
  253. // NOTE otherArguments are not logged to the console on purpose
  254. // to not log the whole log batch
  255. // FIXME check the current logging level (currently not exposed
  256. // by the logger implementation)
  257. // NOTE it is not safe to log whole objects on react-native as
  258. // those contain too many circular references and may crash
  259. // the app.
  260. if (!RTCBrowserType.isReactNative()) {
  261. console && console.debug('reportError', pc, cs, type);
  262. }
  263. } else {
  264. logger.debug('reportError', pc, cs, type, ...args);
  265. }
  266. try {
  267. originalReportError.call(theBackend, pc, cs, type, ...args);
  268. } catch (exception) {
  269. if (type === wrtcFuncNames.applicationLog) {
  270. console && console.error('reportError', exception);
  271. } else {
  272. GlobalOnErrorHandler.callErrorHandler(exception);
  273. }
  274. }
  275. };
  276. /* eslint-enable max-params */
  277. }
  278. /**
  279. * Returns the Set with the currently existing {@link CallStats} instances.
  280. * Lazily initializes the Set to allow any Set polyfills to be applied.
  281. * @type {Set<CallStats>}
  282. */
  283. static get fabrics() {
  284. if (!_fabrics) {
  285. _fabrics = new Set();
  286. }
  287. return _fabrics;
  288. }
  289. /**
  290. * Initializes the CallStats backend. Should be called only if
  291. * {@link CallStats.isBackendInitialized} returns <tt>false</tt>.
  292. * @param {object} options
  293. * @param {String} options.callStatsID CallStats credentials - ID
  294. * @param {String} options.callStatsSecret CallStats credentials - secret
  295. * @param {string} options.aliasName the <tt>aliasName</tt> part of
  296. * the <tt>userID</tt> aka endpoint ID, see CallStats docs for more info.
  297. * @param {string} options.userName the <tt>userName</tt> part of
  298. * the <tt>userID</tt> aka display name, see CallStats docs for more info.
  299. *
  300. */
  301. static initBackend(options) {
  302. if (CallStats.backend) {
  303. throw new Error('CallStats backend has been initialized already!');
  304. }
  305. try {
  306. // In react-native we need to import the callstats module, but
  307. // imports are only allowed at top-level, so we must use require
  308. // here. Sigh.
  309. const CallStatsBackend
  310. = RTCBrowserType.isReactNative()
  311. ? require('react-native-callstats/callstats')
  312. : callstats;
  313. CallStats.backend = new CallStatsBackend();
  314. CallStats._traceAndCatchBackendCalls(CallStats.backend);
  315. CallStats.userID = {
  316. aliasName: options.aliasName,
  317. userName: options.userName
  318. };
  319. CallStats.callStatsID = options.callStatsID;
  320. CallStats.callStatsSecret = options.callStatsSecret;
  321. // userID is generated or given by the origin server
  322. CallStats.backend.initialize(
  323. CallStats.callStatsID,
  324. CallStats.callStatsSecret,
  325. CallStats.userID,
  326. CallStats._initCallback);
  327. return true;
  328. } catch (e) {
  329. // The callstats.io API failed to initialize (e.g. because its
  330. // download did not succeed in general or on time). Further attempts
  331. // to utilize it cannot possibly succeed.
  332. GlobalOnErrorHandler.callErrorHandler(e);
  333. CallStats.backend = null;
  334. logger.error(e);
  335. return false;
  336. }
  337. }
  338. /**
  339. * Checks if the CallStats backend has been created. It does not mean that
  340. * it has been initialized, but only that the API instance has been
  341. * allocated successfully.
  342. * @return {boolean} <tt>true</tt> if backend exists or <tt>false</tt>
  343. * otherwise
  344. */
  345. static isBackendInitialized() {
  346. return Boolean(CallStats.backend);
  347. }
  348. /**
  349. * Notifies CallStats about active device.
  350. * @param {{deviceList: {String:String}}} devicesData list of devices with
  351. * their data
  352. * @param {CallStats} cs callstats instance related to the event
  353. */
  354. static sendActiveDeviceListEvent(devicesData, cs) {
  355. CallStats._reportEvent(cs, fabricEvent.activeDeviceList, devicesData);
  356. }
  357. /**
  358. * Notifies CallStats that there is a log we want to report.
  359. *
  360. * @param {Error} e error to send or {String} message
  361. * @param {CallStats} cs callstats instance related to the error (optional)
  362. */
  363. static sendApplicationLog(e, cs) {
  364. try {
  365. CallStats._reportError(
  366. cs,
  367. wrtcFuncNames.applicationLog,
  368. e,
  369. cs && cs.peerconnection);
  370. } catch (error) {
  371. // If sendApplicationLog fails it should not be printed to
  372. // the logger, because it will try to push the logs again
  373. // (through sendApplicationLog) and an endless loop is created.
  374. if (console && (typeof console.error === 'function')) {
  375. // FIXME send analytics event as well
  376. console.error('sendApplicationLog failed', error);
  377. }
  378. }
  379. }
  380. /**
  381. * Sends the given feedback through CallStats.
  382. *
  383. * @param {string} conferenceID the conference ID for which the feedback
  384. * will be reported.
  385. * @param overallFeedback an integer between 1 and 5 indicating the
  386. * user feedback
  387. * @param detailedFeedback detailed feedback from the user. Not yet used
  388. */
  389. static sendFeedback(conferenceID, overallFeedback, detailedFeedback) {
  390. if (CallStats.backend) {
  391. CallStats.backend.sendUserFeedback(
  392. conferenceID, {
  393. userID: CallStats.userID,
  394. overall: overallFeedback,
  395. comment: detailedFeedback
  396. });
  397. } else {
  398. logger.error('Failed to submit feedback to CallStats - no backend');
  399. }
  400. }
  401. /**
  402. * Notifies CallStats that getUserMedia failed.
  403. *
  404. * @param {Error} e error to send
  405. * @param {CallStats} cs callstats instance related to the error (optional)
  406. */
  407. static sendGetUserMediaFailed(e, cs) {
  408. CallStats._reportError(cs, wrtcFuncNames.getUserMedia, e, null);
  409. }
  410. /**
  411. * Notifies CallStats for mute events
  412. * @param mute {boolean} true for muted and false for not muted
  413. * @param type {String} "audio"/"video"
  414. * @param {CallStats} cs callstats instance related to the event
  415. */
  416. static sendMuteEvent(mute, type, cs) {
  417. let event;
  418. if (type === 'video') {
  419. event = mute ? fabricEvent.videoPause : fabricEvent.videoResume;
  420. } else {
  421. event = mute ? fabricEvent.audioMute : fabricEvent.audioUnmute;
  422. }
  423. CallStats._reportEvent(cs, event);
  424. }
  425. /**
  426. * Creates new CallStats instance that handles all callstats API calls for
  427. * given {@link TraceablePeerConnection}. Each instance is meant to handle
  428. * one CallStats fabric added with 'addFabric' API method for the
  429. * {@link TraceablePeerConnection} instance passed in the constructor.
  430. * @param {TraceablePeerConnection} tpc
  431. * @param {Object} options
  432. * @param {string} options.confID the conference ID that wil be used to
  433. * report the session.
  434. * @param {string} [options.remoteUserID='jitsi'] the remote user ID to
  435. * which given <tt>tpc</tt> is connected.
  436. */
  437. constructor(tpc, options) {
  438. if (!CallStats.backend) {
  439. throw new Error('CallStats backend not intiialized!');
  440. }
  441. this.confID = options.confID;
  442. this.tpc = tpc;
  443. this.peerconnection = tpc.peerconnection;
  444. this.remoteUserID = options.remoteUserID || DEFAULT_REMOTE_USER;
  445. this.hasFabric = false;
  446. CallStats.fabrics.add(this);
  447. if (CallStats.initialized) {
  448. this._addNewFabric();
  449. }
  450. }
  451. /**
  452. * Initializes CallStats fabric by calling "addNewFabric" for
  453. * the peer connection associated with this instance.
  454. * @return {boolean} true if the call was successful or false otherwise.
  455. */
  456. _addNewFabric() {
  457. logger.info('addNewFabric', this.remoteUserID);
  458. try {
  459. const fabricAttributes = {
  460. remoteEndpointType:
  461. this.tpc.isP2P
  462. ? CallStats.backend.endpointType.peer
  463. : CallStats.backend.endpointType.server
  464. };
  465. const ret
  466. = CallStats.backend.addNewFabric(
  467. this.peerconnection,
  468. this.remoteUserID,
  469. CallStats.backend.fabricUsage.multiplex,
  470. this.confID,
  471. fabricAttributes,
  472. CallStats._addNewFabricCallback);
  473. this.hasFabric = true;
  474. const success = ret.status === 'success';
  475. if (!success) {
  476. logger.error('callstats fabric not initilized', ret.message);
  477. }
  478. return success;
  479. } catch (error) {
  480. GlobalOnErrorHandler.callErrorHandler(error);
  481. return false;
  482. }
  483. }
  484. /* eslint-disable max-params */
  485. /**
  486. * Lets CallStats module know where is given SSRC rendered by providing
  487. * renderer tag ID.
  488. * If the lib is not initialized yet queue the call for later, when it's
  489. * ready.
  490. * @param {number} ssrc the SSRC of the stream
  491. * @param {boolean} isLocal indicates whether this the stream is local
  492. * @param {string|null} streamEndpointId if the stream is not local the it
  493. * needs to contain the stream owner's ID
  494. * @param {string} usageLabel meaningful usage label of this stream like
  495. * 'microphone', 'camera' or 'screen'.
  496. * @param {string} containerId the id of media 'audio' or 'video' tag which
  497. * renders the stream.
  498. */
  499. associateStreamWithVideoTag(
  500. ssrc,
  501. isLocal,
  502. streamEndpointId,
  503. usageLabel,
  504. containerId) {
  505. if (!CallStats.backend) {
  506. return;
  507. }
  508. const callStatsId = isLocal ? CallStats.userID : streamEndpointId;
  509. if (CallStats.initialized) {
  510. CallStats.backend.associateMstWithUserID(
  511. this.peerconnection,
  512. callStatsId,
  513. this.confID,
  514. ssrc,
  515. usageLabel,
  516. containerId);
  517. } else {
  518. CallStats.reportsQueue.push({
  519. type: reportType.MST_WITH_USERID,
  520. pc: this.peerconnection,
  521. data: {
  522. callStatsId,
  523. containerId,
  524. ssrc,
  525. usageLabel
  526. }
  527. });
  528. }
  529. }
  530. /* eslint-enable max-params */
  531. /**
  532. * Notifies CallStats that we are the new dominant speaker in the
  533. * conference.
  534. */
  535. sendDominantSpeakerEvent() {
  536. CallStats._reportEvent(this, fabricEvent.dominantSpeaker);
  537. }
  538. /**
  539. * Notifies CallStats that the fabric for the underlying peerconnection was
  540. * closed and no evens should be reported, after this call.
  541. */
  542. sendTerminateEvent() {
  543. if (CallStats.initialized) {
  544. CallStats.backend.sendFabricEvent(
  545. this.peerconnection,
  546. CallStats.backend.fabricEvent.fabricTerminated,
  547. this.confID);
  548. }
  549. CallStats.fabrics.delete(this);
  550. }
  551. /**
  552. * Notifies CallStats for ice connection failed
  553. */
  554. sendIceConnectionFailedEvent() {
  555. CallStats._reportError(
  556. this,
  557. wrtcFuncNames.iceConnectionFailure,
  558. null,
  559. this.peerconnection);
  560. }
  561. /**
  562. * Notifies CallStats that peer connection failed to create offer.
  563. *
  564. * @param {Error} e error to send
  565. */
  566. sendCreateOfferFailed(e) {
  567. CallStats._reportError(
  568. this, wrtcFuncNames.createOffer, e, this.peerconnection);
  569. }
  570. /**
  571. * Notifies CallStats that peer connection failed to create answer.
  572. *
  573. * @param {Error} e error to send
  574. */
  575. sendCreateAnswerFailed(e) {
  576. CallStats._reportError(
  577. this, wrtcFuncNames.createAnswer, e, this.peerconnection);
  578. }
  579. /**
  580. * Sends either resume or hold event for the fabric associated with
  581. * the underlying peerconnection.
  582. * @param {boolean} isResume true to resume or false to hold
  583. */
  584. sendResumeOrHoldEvent(isResume) {
  585. CallStats._reportEvent(
  586. this,
  587. isResume ? fabricEvent.fabricResume : fabricEvent.fabricHold);
  588. }
  589. /**
  590. * Notifies CallStats for screen sharing events
  591. * @param {boolean} start true for starting screen sharing and
  592. * false for not stopping
  593. */
  594. sendScreenSharingEvent(start) {
  595. CallStats._reportEvent(
  596. this,
  597. start ? fabricEvent.screenShareStart : fabricEvent.screenShareStop);
  598. }
  599. /**
  600. * Notifies CallStats that peer connection failed to set local description.
  601. *
  602. * @param {Error} e error to send
  603. */
  604. sendSetLocalDescFailed(e) {
  605. CallStats._reportError(
  606. this, wrtcFuncNames.setLocalDescription, e, this.peerconnection);
  607. }
  608. /**
  609. * Notifies CallStats that peer connection failed to set remote description.
  610. *
  611. * @param {Error} e error to send
  612. */
  613. sendSetRemoteDescFailed(e) {
  614. CallStats._reportError(
  615. this, wrtcFuncNames.setRemoteDescription, e, this.peerconnection);
  616. }
  617. /**
  618. * Notifies CallStats that peer connection failed to add ICE candidate.
  619. *
  620. * @param {Error} e error to send
  621. */
  622. sendAddIceCandidateFailed(e) {
  623. CallStats._reportError(
  624. this, wrtcFuncNames.addIceCandidate, e, this.peerconnection);
  625. }
  626. }
  627. /**
  628. * The CallStats API backend instance
  629. * @type {callstats}
  630. */
  631. CallStats.backend = null;
  632. // some errors/events may happen before CallStats init
  633. // in this case we accumulate them in this array
  634. // and send them to callstats on init
  635. CallStats.reportsQueue = [];
  636. /**
  637. * Whether the library was successfully initialized using its initialize method.
  638. * And whether we had successfully called addNewFabric at least once.
  639. * @type {boolean}
  640. */
  641. CallStats.initialized = false;
  642. /**
  643. * Part of the CallStats credentials - application ID
  644. * @type {string}
  645. */
  646. CallStats.callStatsID = null;
  647. /**
  648. * Part of the CallStats credentials - application secret
  649. * @type {string}
  650. */
  651. CallStats.callStatsSecret = null;
  652. /**
  653. * Local CallStats user ID structure. Can be set only once when
  654. * {@link backend} is initialized, so it's static for the time being.
  655. * See CallStats API for more info:
  656. * https://www.callstats.io/api/#userid
  657. * @type {object}
  658. */
  659. CallStats.userID = null;