Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

CallStats.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. /* global callstats */
  2. import browser from '../browser';
  3. import GlobalOnErrorHandler from '../util/GlobalOnErrorHandler';
  4. const logger = require('@jitsi/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 to 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. * @param {object} options.configParams the set of parameters
  309. * to enable/disable certain features in the library. See CallStats docs for more info.
  310. *
  311. */
  312. static initBackend(options) {
  313. if (CallStats.backend) {
  314. throw new Error('CallStats backend has been initialized already!');
  315. }
  316. try {
  317. const CallStatsBackend = callstats;
  318. CallStats.backend = new CallStatsBackend();
  319. CallStats._traceAndCatchBackendCalls(CallStats.backend);
  320. CallStats.userID = {
  321. aliasName: options.aliasName,
  322. userName: options.userName
  323. };
  324. CallStats.callStatsID = options.callStatsID;
  325. CallStats.callStatsSecret = options.callStatsSecret;
  326. const configParams = { ...options.configParams };
  327. if (options.applicationName) {
  328. configParams.applicationVersion = `${options.applicationName} (${browser.getName()})`;
  329. }
  330. if (options.confID) {
  331. // we first check is there a tenant in the confID
  332. const match = options.confID.match(/.*\/(.*)\/.*/);
  333. // if there is no tenant, we will just set '/'
  334. configParams.siteID = options.siteID || (match && match[1]) || '/';
  335. }
  336. // userID is generated or given by the origin server
  337. CallStats.backend.initialize(
  338. CallStats.callStatsID,
  339. CallStats.callStatsSecret,
  340. CallStats.userID,
  341. CallStats._initCallback,
  342. undefined,
  343. configParams);
  344. return true;
  345. } catch (e) {
  346. // The callstats.io API failed to initialize (e.g. because its
  347. // download did not succeed in general or on time). Further attempts
  348. // to utilize it cannot possibly succeed.
  349. GlobalOnErrorHandler.callErrorHandler(e);
  350. CallStats.backend = null;
  351. logger.error(e);
  352. return false;
  353. }
  354. }
  355. /**
  356. * Checks if the CallStats backend has been created. It does not mean that
  357. * it has been initialized, but only that the API instance has been
  358. * allocated successfully.
  359. * @return {boolean} <tt>true</tt> if backend exists or <tt>false</tt>
  360. * otherwise
  361. */
  362. static isBackendInitialized() {
  363. return Boolean(CallStats.backend);
  364. }
  365. /**
  366. * Notifies CallStats about active device.
  367. * @param {{deviceList: {String:String}}} devicesData list of devices with
  368. * their data
  369. * @param {CallStats} cs callstats instance related to the event
  370. */
  371. static sendActiveDeviceListEvent(devicesData, cs) {
  372. CallStats._reportEvent(cs, fabricEvent.activeDeviceList, devicesData);
  373. }
  374. /**
  375. * Notifies CallStats that there is a log we want to report.
  376. *
  377. * @param {Error} e error to send or {String} message
  378. * @param {CallStats} cs callstats instance related to the error (optional)
  379. */
  380. static sendApplicationLog(e, cs) {
  381. try {
  382. CallStats._reportError(
  383. cs,
  384. wrtcFuncNames.applicationLog,
  385. e,
  386. cs && cs.peerconnection);
  387. } catch (error) {
  388. // If sendApplicationLog fails it should not be printed to
  389. // the logger, because it will try to push the logs again
  390. // (through sendApplicationLog) and an endless loop is created.
  391. if (console && (typeof console.error === 'function')) {
  392. // FIXME send analytics event as well
  393. console.error('sendApplicationLog failed', error);
  394. }
  395. }
  396. }
  397. /**
  398. * Sends the given feedback through CallStats.
  399. *
  400. * @param {string} conferenceID the conference ID for which the feedback
  401. * will be reported.
  402. * @param overall an integer between 1 and 5 indicating the
  403. * user feedback
  404. * @param comment detailed feedback from the user.
  405. */
  406. static sendFeedback(conferenceID, overall, comment) {
  407. return new Promise((resolve, reject) => {
  408. if (CallStats.backend) {
  409. CallStats.backend.sendUserFeedback(
  410. conferenceID,
  411. {
  412. userID: CallStats.userID,
  413. overall,
  414. comment
  415. },
  416. (status, message) => {
  417. if (status === 'success') {
  418. resolve(message);
  419. } else {
  420. reject(message);
  421. }
  422. });
  423. } else {
  424. const reason = 'Failed to submit feedback to CallStats - no backend';
  425. logger.error(reason);
  426. reject(reason);
  427. }
  428. });
  429. }
  430. /**
  431. * Notifies CallStats that getUserMedia failed.
  432. *
  433. * @param {Error} e error to send
  434. * @param {CallStats} cs callstats instance related to the error (optional)
  435. */
  436. static sendGetUserMediaFailed(e, cs) {
  437. CallStats._reportError(cs, wrtcFuncNames.getUserMedia, e, null);
  438. }
  439. /**
  440. * Notifies CallStats for mute events
  441. * @param mute {boolean} true for muted and false for not muted
  442. * @param type {String} "audio"/"video"
  443. * @param {CallStats} cs callstats instance related to the event
  444. */
  445. static sendMuteEvent(mute, type, cs) {
  446. let event;
  447. if (type === 'video') {
  448. event = mute ? fabricEvent.videoPause : fabricEvent.videoResume;
  449. } else {
  450. event = mute ? fabricEvent.audioMute : fabricEvent.audioUnmute;
  451. }
  452. CallStats._reportEvent(cs, event);
  453. }
  454. /**
  455. * Creates new CallStats instance that handles all callstats API calls for
  456. * given {@link TraceablePeerConnection}. Each instance is meant to handle
  457. * one CallStats fabric added with 'addFabric' API method for the
  458. * {@link TraceablePeerConnection} instance passed in the constructor.
  459. * @param {TraceablePeerConnection} tpc
  460. * @param {Object} options
  461. * @param {string} options.confID the conference ID that wil be used to
  462. * report the session.
  463. * @param {string} [options.remoteUserID='jitsi'] the remote user ID to
  464. * which given <tt>tpc</tt> is connected.
  465. */
  466. constructor(tpc, options) {
  467. this.confID = options.confID;
  468. this.tpc = tpc;
  469. this.peerconnection = tpc.peerconnection;
  470. this.remoteUserID = options.remoteUserID || DEFAULT_REMOTE_USER;
  471. this.hasFabric = false;
  472. CallStats.fabrics.add(this);
  473. if (CallStats.backendInitialized) {
  474. this._addNewFabric();
  475. // if this is the first fabric let's try to empty the
  476. // report queue. Reports all events that we recorded between
  477. // backend initialization and receiving the first fabric
  478. if (CallStats.fabrics.size === 1) {
  479. CallStats._emptyReportQueue(this);
  480. }
  481. }
  482. }
  483. /**
  484. * Initializes CallStats fabric by calling "addNewFabric" for
  485. * the peer connection associated with this instance.
  486. * @return {boolean} true if the call was successful or false otherwise.
  487. */
  488. _addNewFabric() {
  489. logger.info('addNewFabric', this.remoteUserID);
  490. try {
  491. const fabricAttributes = {
  492. remoteEndpointType:
  493. this.tpc.isP2P
  494. ? CallStats.backend.endpointType.peer
  495. : CallStats.backend.endpointType.server
  496. };
  497. const ret
  498. = CallStats.backend.addNewFabric(
  499. this.peerconnection,
  500. this.remoteUserID,
  501. CallStats.backend.fabricUsage.multiplex,
  502. this.confID,
  503. fabricAttributes,
  504. CallStats._addNewFabricCallback);
  505. this.hasFabric = true;
  506. const success = ret.status === 'success';
  507. if (!success) {
  508. logger.error('callstats fabric not initilized', ret.message);
  509. }
  510. return success;
  511. } catch (error) {
  512. GlobalOnErrorHandler.callErrorHandler(error);
  513. return false;
  514. }
  515. }
  516. /* eslint-disable max-params */
  517. /**
  518. * Lets CallStats module know where is given SSRC rendered by providing
  519. * renderer tag ID.
  520. * If the lib is not initialized yet queue the call for later, when it's
  521. * ready.
  522. * @param {number} ssrc the SSRC of the stream
  523. * @param {boolean} isLocal indicates whether this the stream is local
  524. * @param {string|null} streamEndpointId if the stream is not local the it
  525. * needs to contain the stream owner's ID
  526. * @param {string} usageLabel meaningful usage label of this stream like
  527. * 'microphone', 'camera' or 'screen'.
  528. * @param {string} containerId the id of media 'audio' or 'video' tag which
  529. * renders the stream.
  530. */
  531. associateStreamWithVideoTag(
  532. ssrc,
  533. isLocal,
  534. streamEndpointId,
  535. usageLabel,
  536. containerId) {
  537. if (!CallStats.backend) {
  538. return;
  539. }
  540. const callStatsId = isLocal ? CallStats.userID : streamEndpointId;
  541. if (CallStats.backendInitialized) {
  542. CallStats.backend.associateMstWithUserID(
  543. this.peerconnection,
  544. callStatsId,
  545. this.confID,
  546. ssrc,
  547. usageLabel,
  548. containerId);
  549. } else {
  550. CallStats.reportsQueue.push({
  551. type: reportType.MST_WITH_USERID,
  552. pc: this.peerconnection,
  553. data: {
  554. callStatsId,
  555. containerId,
  556. ssrc,
  557. usageLabel
  558. }
  559. });
  560. }
  561. }
  562. /* eslint-enable max-params */
  563. /**
  564. * Notifies CallStats that we are the new dominant speaker in the
  565. * conference.
  566. */
  567. sendDominantSpeakerEvent() {
  568. CallStats._reportEvent(this, fabricEvent.dominantSpeaker);
  569. }
  570. /**
  571. * Notifies CallStats that the fabric for the underlying peerconnection was
  572. * closed and no evens should be reported, after this call.
  573. */
  574. sendTerminateEvent() {
  575. if (CallStats.backendInitialized) {
  576. CallStats.backend.sendFabricEvent(
  577. this.peerconnection,
  578. CallStats.backend.fabricEvent.fabricTerminated,
  579. this.confID);
  580. }
  581. CallStats.fabrics.delete(this);
  582. }
  583. /**
  584. * Notifies CallStats for ice connection failed
  585. */
  586. sendIceConnectionFailedEvent() {
  587. CallStats._reportError(
  588. this,
  589. wrtcFuncNames.iceConnectionFailure,
  590. null,
  591. this.peerconnection);
  592. }
  593. /**
  594. * Notifies CallStats that peer connection failed to create offer.
  595. *
  596. * @param {Error} e error to send
  597. */
  598. sendCreateOfferFailed(e) {
  599. CallStats._reportError(
  600. this, wrtcFuncNames.createOffer, e, this.peerconnection);
  601. }
  602. /**
  603. * Notifies CallStats that peer connection failed to create answer.
  604. *
  605. * @param {Error} e error to send
  606. */
  607. sendCreateAnswerFailed(e) {
  608. CallStats._reportError(
  609. this, wrtcFuncNames.createAnswer, e, this.peerconnection);
  610. }
  611. /**
  612. * Sends either resume or hold event for the fabric associated with
  613. * the underlying peerconnection.
  614. * @param {boolean} isResume true to resume or false to hold
  615. */
  616. sendResumeOrHoldEvent(isResume) {
  617. CallStats._reportEvent(
  618. this,
  619. isResume ? fabricEvent.fabricResume : fabricEvent.fabricHold);
  620. }
  621. /**
  622. * Notifies CallStats for screen sharing events
  623. * @param {boolean} start true for starting screen sharing and
  624. * false for not stopping
  625. * @param {string|null} ssrc - optional ssrc value, used only when
  626. * starting screen sharing.
  627. */
  628. sendScreenSharingEvent(start, ssrc) {
  629. let eventData;
  630. if (ssrc) {
  631. eventData = { ssrc };
  632. }
  633. CallStats._reportEvent(
  634. this,
  635. start ? fabricEvent.screenShareStart : fabricEvent.screenShareStop,
  636. eventData);
  637. }
  638. /**
  639. * Notifies CallStats that peer connection failed to set local description.
  640. *
  641. * @param {Error} e error to send
  642. */
  643. sendSetLocalDescFailed(e) {
  644. CallStats._reportError(
  645. this, wrtcFuncNames.setLocalDescription, e, this.peerconnection);
  646. }
  647. /**
  648. * Notifies CallStats that peer connection failed to set remote description.
  649. *
  650. * @param {Error} e error to send
  651. */
  652. sendSetRemoteDescFailed(e) {
  653. CallStats._reportError(
  654. this, wrtcFuncNames.setRemoteDescription, e, this.peerconnection);
  655. }
  656. /**
  657. * Notifies CallStats that peer connection failed to add ICE candidate.
  658. *
  659. * @param {Error} e error to send
  660. */
  661. sendAddIceCandidateFailed(e) {
  662. CallStats._reportError(
  663. this, wrtcFuncNames.addIceCandidate, e, this.peerconnection);
  664. }
  665. }
  666. /**
  667. * The CallStats API backend instance
  668. * @type {callstats}
  669. */
  670. CallStats.backend = null;
  671. // some errors/events may happen before CallStats init
  672. // in this case we accumulate them in this array
  673. // and send them to callstats on init
  674. CallStats.reportsQueue = [];
  675. /**
  676. * Whether the library was successfully initialized(the backend) using its
  677. * initialize method.
  678. * @type {boolean}
  679. */
  680. CallStats.backendInitialized = false;
  681. /**
  682. * Part of the CallStats credentials - application ID
  683. * @type {string}
  684. */
  685. CallStats.callStatsID = null;
  686. /**
  687. * Part of the CallStats credentials - application secret
  688. * @type {string}
  689. */
  690. CallStats.callStatsSecret = null;
  691. /**
  692. * Local CallStats user ID structure. Can be set only once when
  693. * {@link backend} is initialized, so it's static for the time being.
  694. * See CallStats API for more info:
  695. * https://www.callstats.io/api/#userid
  696. * @type {object}
  697. */
  698. CallStats.userID = null;