rn-pendo-sdk
Version:
Pendo Mobile React Native SDK
1 lines • 3.55 kB
JavaScript
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.ScanCoordinator=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _common=require("./common");var _pendoLogger=require("./pendoLogger");var ScanCoordinator=exports.ScanCoordinator=function(){function ScanCoordinator(){(0,_classCallCheck2.default)(this,ScanCoordinator);this.activeScanRequests=false;this.activeIntegrationType=null;this.lastIntegrationType=null;this.lastScanTime=0;this.SCAN_THROTTLE_MS=300;}return(0,_createClass2.default)(ScanCoordinator,[{key:"canScanNow",value:function canScanNow(integrationType,event){var now=Date.now();var lastScan=this.lastScanTime;var timeBetweenScans=now-lastScan;if(lastScan>0){_pendoLogger.Logger.debug(`Scan requested after ${timeBetweenScans} ms`);}if(this.activeScanRequests){_pendoLogger.Logger.debug(`Scan dropped for ${integrationType} with event ${event} due to active scan`);return false;}else if(event===_common.Consts.kOnStateChange&&integrationType!==this.lastIntegrationType){return true;}else if(event===_common.Consts.kOnModalStateVisible){if(integrationType===this.lastIntegrationType){return true;}else{_pendoLogger.Logger.debug(`Scan dropped for ${integrationType} with event ${event} due to visible modal triggered but active integration is ${this.lastIntegrationType}`);return false;}}else if(now-lastScan<this.SCAN_THROTTLE_MS){_pendoLogger.Logger.debug(`Scan dropped for ${integrationType} with event ${event} due to frequent scanning`);return false;}else if(event===_common.Consts.kOnDynamicContentRequestAnalyzer&&integrationType!==this.lastIntegrationType){_pendoLogger.Logger.debug(`Scan dropped for ${integrationType} with event ${event} due to dynamic content request but active integration is ${this.lastIntegrationType}`);return false;}else if(event===_common.Consts.kOnCaptureRequestAnalyzer&&integrationType!==this.lastIntegrationType){_pendoLogger.Logger.debug(`Scan dropped for ${integrationType} with event ${event} due to capture request but active integration is ${this.lastIntegrationType}`);return false;}return true;}},{key:"requestScanWithContext",value:function requestScanWithContext(integrationType,event){var now=Date.now();if(!this.canScanNow(integrationType,event)){return false;}this.activeScanRequests=true;this.activeIntegrationType=integrationType;this.lastScanTime=now;_pendoLogger.Logger.debug(`Scan granted for ${integrationType} with event ${event}`);return true;}},{key:"completeScan",value:function completeScan(){if(!this.activeScanRequests&&this.activeIntegrationType===null){_pendoLogger.Logger.debug('No active scan to complete');return;}this.lastIntegrationType=this.activeIntegrationType;this.activeIntegrationType=null;this.activeScanRequests=false;this.lastScanTime=Date.now();_pendoLogger.Logger.debug(`Scan completed for ${this.lastIntegrationType}`);}},{key:"isScanInProgress",value:function isScanInProgress(){return this.activeScanRequests;}},{key:"reset",value:function reset(){this.activeScanRequests=false;this.lastIntegrationType=null;this.activeIntegrationType=null;this.lastScanTime=0;_pendoLogger.Logger.debug('ScanCoordinator reset');}}],[{key:"getInstance",value:function getInstance(){if(!ScanCoordinator.instance){ScanCoordinator.instance=new ScanCoordinator();}return ScanCoordinator.instance;}}]);}();ScanCoordinator.instance=null;