react-live-chat-loader
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -38,23 +38,16 @@ "use strict"; | ||
if (connection && (connection.saveData || /2g/.test(connection.effectiveType))) return; | ||
var idleCountThreshold = parseInt(idlePeriod, 10) / 50; | ||
if (isNaN(idleCountThreshold)) return; // deadline.timeRemaining() has an upper limit of 50 milliseconds | ||
var idleThreshold = parseInt(idlePeriod, 10); | ||
if (isNaN(idleThreshold)) return; // deadline.timeRemaining() has an upper limit of 50 milliseconds | ||
// We want to ensure the page has been idle for a significant period of time | ||
// Therefore we count consecutive maximum timeRemaining counts and load chat when we reach our threshold | ||
var idleCounts = 0; | ||
var elapsedIdlePeriod = 0; | ||
var scheduleLoadChat = function scheduleLoadChat(deadline) { | ||
if (idleCounts > idleCountThreshold) { | ||
loadChat({ | ||
open: false | ||
}); | ||
} else if (deadline.timeRemaining() > 49) { | ||
// no activity has occurred, increment idle count | ||
idleCounts++; | ||
requestIdleCallback(scheduleLoadChat); | ||
} else { | ||
// some activity has occurred, reset idle count | ||
idleCounts = 0; | ||
requestIdleCallback(scheduleLoadChat); | ||
} | ||
if (elapsedIdlePeriod > idleThreshold) return loadChat({ | ||
open: false | ||
}); | ||
var timeRemaining = deadline.timeRemaining(); | ||
if (timeRemaining > 49) elapsedIdlePeriod += timeRemaining; | ||
requestIdleCallback(scheduleLoadChat); | ||
}; | ||
@@ -69,3 +62,3 @@ | ||
}); | ||
}, idleCountThreshold * 50); | ||
}, idleThreshold * 2); | ||
} | ||
@@ -72,0 +65,0 @@ }, []); |
{ | ||
"name": "react-live-chat-loader", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "Implement live chat in your react app without taking a performance hit.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51552
776