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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. /* global callstats */
  2. import browser from '../browser';
  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. CallStats.backendInitialized = true;
  99. // I hate that
  100. let atLeastOneFabric = false;
  101. let defaultInstance = null;
  102. for (const callStatsInstance of CallStats.fabrics.values()) {
  103. if (!callStatsInstance.hasFabric) {
  104. logger.debug('addNewFabric - initCallback');
  105. if (callStatsInstance._addNewFabric()) {
  106. atLeastOneFabric = true;
  107. if (!defaultInstance) {
  108. defaultInstance = callStatsInstance;
  109. }
  110. }
  111. }
  112. }
  113. if (!atLeastOneFabric) {
  114. return;
  115. }
  116. CallStats._emptyReportQueue(defaultInstance);
  117. }
  118. /**
  119. * Empties report queue.
  120. *
  121. * @param {CallStats} csInstance - The callstats instance.
  122. * @private
  123. */
  124. static _emptyReportQueue(csInstance) {
  125. // There is no conference ID nor a PeerConnection available when some of
  126. // the events are scheduled on the reportsQueue, so those will be
  127. // reported on the first initialized fabric.
  128. const defaultConfID = csInstance.confID;
  129. const defaultPC = csInstance.peerconnection;
  130. // notify callstats about failures if there were any
  131. for (const report of CallStats.reportsQueue) {
  132. if (report.type === reportType.ERROR) {
  133. const errorData = report.data;
  134. CallStats._reportError(
  135. csInstance,
  136. errorData.type,
  137. errorData.error,
  138. errorData.pc || defaultPC);
  139. } else if (report.type === reportType.EVENT) {
  140. // if we have and event to report and we failed to add
  141. // fabric this event will not be reported anyway, returning
  142. // an error
  143. const eventData = report.data;
  144. CallStats.backend.sendFabricEvent(
  145. report.pc || defaultPC,
  146. eventData.event,
  147. defaultConfID,
  148. eventData.eventData);
  149. } else if (report.type === reportType.MST_WITH_USERID) {
  150. const data = report.data;
  151. CallStats.backend.associateMstWithUserID(
  152. report.pc || defaultPC,
  153. data.callStatsId,
  154. defaultConfID,
  155. data.ssrc,
  156. data.usageLabel,
  157. data.containerId
  158. );
  159. }
  160. }
  161. CallStats.reportsQueue.length = 0;
  162. }
  163. /* eslint-disable max-params */
  164. /**
  165. * Reports an error to callstats.
  166. *
  167. * @param {CallStats} [cs]
  168. * @param type the type of the error, which will be one of the wrtcFuncNames
  169. * @param error the error
  170. * @param pc the peerconnection
  171. * @private
  172. */
  173. static _reportError(cs, type, error, pc) {
  174. let _error = error;
  175. if (!_error) {
  176. logger.warn('No error is passed!');
  177. _error = new Error('Unknown error');
  178. }
  179. if (CallStats.backendInitialized && cs) {
  180. CallStats.backend.reportError(pc, cs.confID, type, _error);
  181. } else {
  182. CallStats.reportsQueue.push({
  183. type: reportType.ERROR,
  184. data: {
  185. error: _error,
  186. pc,
  187. type
  188. }
  189. });
  190. }
  191. // else just ignore it
  192. }
  193. /* eslint-enable max-params */
  194. /**
  195. * Reports an error to callstats.
  196. *
  197. * @param {CallStats} cs
  198. * @param event the type of the event, which will be one of the fabricEvent
  199. * @param eventData additional data to pass to event
  200. * @private
  201. */
  202. static _reportEvent(cs, event, eventData) {
  203. const pc = cs && cs.peerconnection;
  204. const confID = cs && cs.confID;
  205. if (CallStats.backendInitialized && cs) {
  206. CallStats.backend.sendFabricEvent(pc, event, confID, eventData);
  207. } else {
  208. CallStats.reportsQueue.push({
  209. confID,
  210. pc,
  211. type: reportType.EVENT,
  212. data: { event,
  213. eventData }
  214. });
  215. }
  216. }
  217. /**
  218. * Wraps some of the CallStats API method and logs their calls with
  219. * arguments on the debug logging level. Also wraps some of the backend
  220. * methods execution into try catch blocks to not crash the app in case
  221. * there is a problem with the backend itself.
  222. * @param {callstats} theBackend
  223. * @private
  224. */
  225. static _traceAndCatchBackendCalls(theBackend) {
  226. const tryCatchMethods = [
  227. 'associateMstWithUserID',
  228. 'sendFabricEvent',
  229. 'sendUserFeedback'
  230. // 'reportError', - this one needs special handling - see code below
  231. ];
  232. for (const methodName of tryCatchMethods) {
  233. const originalMethod = theBackend[methodName];
  234. theBackend[methodName] = function(...theArguments) {
  235. try {
  236. return originalMethod.apply(theBackend, theArguments);
  237. } catch (e) {
  238. GlobalOnErrorHandler.callErrorHandler(e);
  239. }
  240. };
  241. }
  242. const debugMethods = [
  243. 'associateMstWithUserID',
  244. 'sendFabricEvent',
  245. 'sendUserFeedback'
  246. // 'reportError', - this one needs special handling - see code below
  247. ];
  248. for (const methodName of debugMethods) {
  249. const originalMethod = theBackend[methodName];
  250. theBackend[methodName] = function(...theArguments) {
  251. logger.debug(methodName, theArguments);
  252. originalMethod.apply(theBackend, theArguments);
  253. };
  254. }
  255. const originalReportError = theBackend.reportError;
  256. /* eslint-disable max-params */
  257. theBackend.reportError = function(pc, cs, type, ...args) {
  258. // Logs from the logger are submitted on the applicationLog event
  259. // "type". Logging the arguments on the logger will create endless
  260. // loop, because it will put all the logs to the logger queue again.
  261. if (type === wrtcFuncNames.applicationLog) {
  262. // NOTE otherArguments are not logged to the console on purpose
  263. // to not log the whole log batch
  264. // FIXME check the current logging level (currently not exposed
  265. // by the logger implementation)
  266. // NOTE it is not safe to log whole objects on react-native as
  267. // those contain too many circular references and may crash
  268. // the app.
  269. if (!browser.isReactNative()) {
  270. console && console.debug('reportError', pc, cs, type);
  271. }
  272. } else {
  273. logger.debug('reportError', pc, cs, type, ...args);
  274. }
  275. try {
  276. originalReportError.call(theBackend, pc, cs, type, ...args);
  277. } catch (exception) {
  278. if (type === wrtcFuncNames.applicationLog) {
  279. console && console.error('reportError', exception);
  280. } else {
  281. GlobalOnErrorHandler.callErrorHandler(exception);
  282. }
  283. }
  284. };
  285. /* eslint-enable max-params */
  286. }
  287. /**
  288. * Returns the Set with the currently existing {@link CallStats} instances.
  289. * Lazily initializes the Set to allow any Set polyfills to be applied.
  290. * @type {Set<CallStats>}
  291. */
  292. static get fabrics() {
  293. if (!_fabrics) {
  294. _fabrics = new Set();
  295. }
  296. return _fabrics;
  297. }
  298. /**
  299. * Initializes the CallStats backend. Should be called only if
  300. * {@link CallStats.isBackendInitialized} returns <tt>false</tt>.
  301. * @param {object} options
  302. * @param {String} options.callStatsID CallStats credentials - ID
  303. * @param {String} options.callStatsSecret CallStats credentials - secret
  304. * @param {string} options.aliasName the <tt>aliasName</tt> part of
  305. * the <tt>userID</tt> aka endpoint ID, see CallStats docs for more info.
  306. * @param {string} options.userName the <tt>userName</tt> part of
  307. * the <tt>userID</tt> aka display name, see CallStats docs for more info.
  308. *
  309. */
  310. static initBackend(options) {
  311. if (CallStats.backend) {
  312. throw new Error('CallStats backend has been initialized already!');
  313. }
  314. try {
  315. const CallStatsBackend = callstats;
  316. CallStats.backend = new CallStatsBackend();
  317. CallStats._traceAndCatchBackendCalls(CallStats.backend);
  318. CallStats.userID = {
  319. aliasName: options.aliasName,
  320. userName: options.userName
  321. };
  322. CallStats.callStatsID = options.callStatsID;
  323. CallStats.callStatsSecret = options.callStatsSecret;
  324. let configParams;
  325. if (options.applicationName) {
  326. configParams = {
  327. applicationVersion:
  328. `${options.applicationName} (${
  329. browser.getName()})`
  330. };
  331. }
  332. if (options.confID) {
  333. // we first check is there a tenant in the confID
  334. const match = options.confID.match(/.*\/(.*)\/.*/);
  335. // if there is no tenant, we will just set '/'
  336. configParams.siteID = options.siteID || (match && match[1]) || '/';
  337. }
  338. // userID is generated or given by the origin server
  339. CallStats.backend.initialize(
  340. CallStats.callStatsID,
  341. CallStats.callStatsSecret,
  342. CallStats.userID,
  343. CallStats._initCallback,
  344. undefined,
  345. configParams);
  346. const getWiFiStatsMethod = options.getWiFiStatsMethod;
  347. if (getWiFiStatsMethod) {
  348. CallStats.backend.attachWifiStatsHandler(getWiFiStatsMethod);
  349. getWiFiStatsMethod().then(result => {
  350. if (result) {
  351. logger.info('Reported wifi addresses:'
  352. , JSON.parse(result).addresses);
  353. }
  354. })
  355. .catch(() => {});// eslint-disable-line no-empty-function
  356. }
  357. return true;
  358. } catch (e) {
  359. // The callstats.io API failed to initialize (e.g. because its
  360. // download did not succeed in general or on time). Further attempts
  361. // to utilize it cannot possibly succeed.
  362. GlobalOnErrorHandler.callErrorHandler(e);
  363. CallStats.backend = null;
  364. logger.error(e);
  365. return false;
  366. }
  367. }
  368. /**
  369. * Checks if the CallStats backend has been created. It does not mean that
  370. * it has been initialized, but only that the API instance has been
  371. * allocated successfully.
  372. * @return {boolean} <tt>true</tt> if backend exists or <tt>false</tt>
  373. * otherwise
  374. */
  375. static isBackendInitialized() {
  376. return Boolean(CallStats.backend);
  377. }
  378. /**
  379. * Notifies CallStats about active device.
  380. * @param {{deviceList: {String:String}}} devicesData list of devices with
  381. * their data
  382. * @param {CallStats} cs callstats instance related to the event
  383. */
  384. static sendActiveDeviceListEvent(devicesData, cs) {
  385. CallStats._reportEvent(cs, fabricEvent.activeDeviceList, devicesData);
  386. }
  387. /**
  388. * Notifies CallStats that there is a log we want to report.
  389. *
  390. * @param {Error} e error to send or {String} message
  391. * @param {CallStats} cs callstats instance related to the error (optional)
  392. */
  393. static sendApplicationLog(e, cs) {
  394. try {
  395. CallStats._reportError(
  396. cs,
  397. wrtcFuncNames.applicationLog,
  398. e,
  399. cs && cs.peerconnection);
  400. } catch (error) {
  401. // If sendApplicationLog fails it should not be printed to
  402. // the logger, because it will try to push the logs again
  403. // (through sendApplicationLog) and an endless loop is created.
  404. if (console && (typeof console.error === 'function')) {
  405. // FIXME send analytics event as well
  406. console.error('sendApplicationLog failed', error);
  407. }
  408. }
  409. }
  410. /**
  411. * Sends the given feedback through CallStats.
  412. *
  413. * @param {string} conferenceID the conference ID for which the feedback
  414. * will be reported.
  415. * @param overall an integer between 1 and 5 indicating the
  416. * user feedback
  417. * @param comment detailed feedback from the user.
  418. */
  419. static sendFeedback(conferenceID, overall, comment) {
  420. return new Promise((resolve, reject) => {
  421. if (CallStats.backend) {
  422. CallStats.backend.sendUserFeedback(
  423. conferenceID,
  424. {
  425. userID: CallStats.userID,
  426. overall,
  427. comment
  428. },
  429. (status, message) => {
  430. if (status === 'success') {
  431. resolve(message);
  432. } else {
  433. reject(message);
  434. }
  435. });
  436. } else {
  437. const reason = 'Failed to submit feedback to CallStats - no backend';
  438. logger.error(reason);
  439. reject(reason);
  440. }
  441. });
  442. }
  443. /**
  444. * Notifies CallStats that getUserMedia failed.
  445. *
  446. * @param {Error} e error to send
  447. * @param {CallStats} cs callstats instance related to the error (optional)
  448. */
  449. static sendGetUserMediaFailed(e, cs) {
  450. CallStats._reportError(cs, wrtcFuncNames.getUserMedia, e, null);
  451. }
  452. /**
  453. * Notifies CallStats for mute events
  454. * @param mute {boolean} true for muted and false for not muted
  455. * @param type {String} "audio"/"video"
  456. * @param {CallStats} cs callstats instance related to the event
  457. */
  458. static sendMuteEvent(mute, type, cs) {
  459. let event;
  460. if (type === 'video') {
  461. event = mute ? fabricEvent.videoPause : fabricEvent.videoResume;
  462. } else {
  463. event = mute ? fabricEvent.audioMute : fabricEvent.audioUnmute;
  464. }
  465. CallStats._reportEvent(cs, event);
  466. }
  467. /**
  468. * Creates new CallStats instance that handles all callstats API calls for
  469. * given {@link TraceablePeerConnection}. Each instance is meant to handle
  470. * one CallStats fabric added with 'addFabric' API method for the
  471. * {@link TraceablePeerConnection} instance passed in the constructor.
  472. * @param {TraceablePeerConnection} tpc
  473. * @param {Object} options
  474. * @param {string} options.confID the conference ID that wil be used to
  475. * report the session.
  476. * @param {string} [options.remoteUserID='jitsi'] the remote user ID to
  477. * which given <tt>tpc</tt> is connected.
  478. */
  479. constructor(tpc, options) {
  480. this.confID = options.confID;
  481. this.tpc = tpc;
  482. this.peerconnection = tpc.peerconnection;
  483. this.remoteUserID = options.remoteUserID || DEFAULT_REMOTE_USER;
  484. this.hasFabric = false;
  485. CallStats.fabrics.add(this);
  486. if (CallStats.backendInitialized) {
  487. this._addNewFabric();
  488. // if this is the first fabric let's try to empty the
  489. // report queue. Reports all events that we recorded between
  490. // backend initialization and receiving the first fabric
  491. if (CallStats.fabrics.size === 1) {
  492. CallStats._emptyReportQueue(this);
  493. }
  494. }
  495. }
  496. /**
  497. * Initializes CallStats fabric by calling "addNewFabric" for
  498. * the peer connection associated with this instance.
  499. * @return {boolean} true if the call was successful or false otherwise.
  500. */
  501. _addNewFabric() {
  502. logger.info('addNewFabric', this.remoteUserID);
  503. try {
  504. const fabricAttributes = {
  505. remoteEndpointType:
  506. this.tpc.isP2P
  507. ? CallStats.backend.endpointType.peer
  508. : CallStats.backend.endpointType.server
  509. };
  510. const ret
  511. = CallStats.backend.addNewFabric(
  512. this.peerconnection,
  513. this.remoteUserID,
  514. CallStats.backend.fabricUsage.multiplex,
  515. this.confID,
  516. fabricAttributes,
  517. CallStats._addNewFabricCallback);
  518. this.hasFabric = true;
  519. const success = ret.status === 'success';
  520. if (!success) {
  521. logger.error('callstats fabric not initilized', ret.message);
  522. }
  523. return success;
  524. } catch (error) {
  525. GlobalOnErrorHandler.callErrorHandler(error);
  526. return false;
  527. }
  528. }
  529. /* eslint-disable max-params */
  530. /**
  531. * Lets CallStats module know where is given SSRC rendered by providing
  532. * renderer tag ID.
  533. * If the lib is not initialized yet queue the call for later, when it's
  534. * ready.
  535. * @param {number} ssrc the SSRC of the stream
  536. * @param {boolean} isLocal indicates whether this the stream is local
  537. * @param {string|null} streamEndpointId if the stream is not local the it
  538. * needs to contain the stream owner's ID
  539. * @param {string} usageLabel meaningful usage label of this stream like
  540. * 'microphone', 'camera' or 'screen'.
  541. * @param {string} containerId the id of media 'audio' or 'video' tag which
  542. * renders the stream.
  543. */
  544. associateStreamWithVideoTag(
  545. ssrc,
  546. isLocal,
  547. streamEndpointId,
  548. usageLabel,
  549. containerId) {
  550. if (!CallStats.backend) {
  551. return;
  552. }
  553. const callStatsId = isLocal ? CallStats.userID : streamEndpointId;
  554. if (CallStats.backendInitialized) {
  555. CallStats.backend.associateMstWithUserID(
  556. this.peerconnection,
  557. callStatsId,
  558. this.confID,
  559. ssrc,
  560. usageLabel,
  561. containerId);
  562. } else {
  563. CallStats.reportsQueue.push({
  564. type: reportType.MST_WITH_USERID,
  565. pc: this.peerconnection,
  566. data: {
  567. callStatsId,
  568. containerId,
  569. ssrc,
  570. usageLabel
  571. }
  572. });
  573. }
  574. }
  575. /* eslint-enable max-params */
  576. /**
  577. * Notifies CallStats that we are the new dominant speaker in the
  578. * conference.
  579. */
  580. sendDominantSpeakerEvent() {
  581. CallStats._reportEvent(this, fabricEvent.dominantSpeaker);
  582. }
  583. /**
  584. * Notifies CallStats that the fabric for the underlying peerconnection was
  585. * closed and no evens should be reported, after this call.
  586. */
  587. sendTerminateEvent() {
  588. if (CallStats.backendInitialized) {
  589. CallStats.backend.sendFabricEvent(
  590. this.peerconnection,
  591. CallStats.backend.fabricEvent.fabricTerminated,
  592. this.confID);
  593. }
  594. CallStats.fabrics.delete(this);
  595. }
  596. /**
  597. * Notifies CallStats for ice connection failed
  598. */
  599. sendIceConnectionFailedEvent() {
  600. CallStats._reportError(
  601. this,
  602. wrtcFuncNames.iceConnectionFailure,
  603. null,
  604. this.peerconnection);
  605. }
  606. /**
  607. * Notifies CallStats that peer connection failed to create offer.
  608. *
  609. * @param {Error} e error to send
  610. */
  611. sendCreateOfferFailed(e) {
  612. CallStats._reportError(
  613. this, wrtcFuncNames.createOffer, e, this.peerconnection);
  614. }
  615. /**
  616. * Notifies CallStats that peer connection failed to create answer.
  617. *
  618. * @param {Error} e error to send
  619. */
  620. sendCreateAnswerFailed(e) {
  621. CallStats._reportError(
  622. this, wrtcFuncNames.createAnswer, e, this.peerconnection);
  623. }
  624. /**
  625. * Sends either resume or hold event for the fabric associated with
  626. * the underlying peerconnection.
  627. * @param {boolean} isResume true to resume or false to hold
  628. */
  629. sendResumeOrHoldEvent(isResume) {
  630. CallStats._reportEvent(
  631. this,
  632. isResume ? fabricEvent.fabricResume : fabricEvent.fabricHold);
  633. }
  634. /**
  635. * Notifies CallStats for screen sharing events
  636. * @param {boolean} start true for starting screen sharing and
  637. * false for not stopping
  638. * @param {string|null} ssrc - optional ssrc value, used only when
  639. * starting screen sharing.
  640. */
  641. sendScreenSharingEvent(start, ssrc) {
  642. let eventData;
  643. if (ssrc) {
  644. eventData = { ssrc };
  645. }
  646. CallStats._reportEvent(
  647. this,
  648. start ? fabricEvent.screenShareStart : fabricEvent.screenShareStop,
  649. eventData);
  650. }
  651. /**
  652. * Notifies CallStats that peer connection failed to set local description.
  653. *
  654. * @param {Error} e error to send
  655. */
  656. sendSetLocalDescFailed(e) {
  657. CallStats._reportError(
  658. this, wrtcFuncNames.setLocalDescription, e, this.peerconnection);
  659. }
  660. /**
  661. * Notifies CallStats that peer connection failed to set remote description.
  662. *
  663. * @param {Error} e error to send
  664. */
  665. sendSetRemoteDescFailed(e) {
  666. CallStats._reportError(
  667. this, wrtcFuncNames.setRemoteDescription, e, this.peerconnection);
  668. }
  669. /**
  670. * Notifies CallStats that peer connection failed to add ICE candidate.
  671. *
  672. * @param {Error} e error to send
  673. */
  674. sendAddIceCandidateFailed(e) {
  675. CallStats._reportError(
  676. this, wrtcFuncNames.addIceCandidate, e, this.peerconnection);
  677. }
  678. }
  679. /**
  680. * The CallStats API backend instance
  681. * @type {callstats}
  682. */
  683. CallStats.backend = null;
  684. // some errors/events may happen before CallStats init
  685. // in this case we accumulate them in this array
  686. // and send them to callstats on init
  687. CallStats.reportsQueue = [];
  688. /**
  689. * Whether the library was successfully initialized(the backend) using its
  690. * initialize method.
  691. * @type {boolean}
  692. */
  693. CallStats.backendInitialized = false;
  694. /**
  695. * Part of the CallStats credentials - application ID
  696. * @type {string}
  697. */
  698. CallStats.callStatsID = null;
  699. /**
  700. * Part of the CallStats credentials - application secret
  701. * @type {string}
  702. */
  703. CallStats.callStatsSecret = null;
  704. /**
  705. * Local CallStats user ID structure. Can be set only once when
  706. * {@link backend} is initialized, so it's static for the time being.
  707. * See CallStats API for more info:
  708. * https://www.callstats.io/api/#userid
  709. * @type {object}
  710. */
  711. CallStats.userID = null;