I would like to implement countdown timers in my project. However, I would like the countdown to be synchronized across all users. For example, if the countdown at user A is 03:05, the countdown at user B should be the same 03:05. I have been able to create a countdown timer, but I am not able to synchronize across all users. I would like to have an interval of 5 minutes, once the 5 minutes expires, the timer will restart at 5 min, 4:49, 4:48 etc to zero. This should be the same across all users or devices.
<script>
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
setInterval(function () {
minutes = parseInt(timer / 60, 10);
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
if (--timer < 0) {
timer = duration;
}
}, 1000);
}
window.onload = function () {
var fiveMinutes = 60 * 1,
display = document.querySelector('#demo');
startTimer(fiveMinutes, display);
};
</script>