Add time to the original message. Let's say that songs are an object with {"time" : timeString, "songs" : songsList} .
If we believe that the device time is correct, you can calculate the time required to move the information, and then simply use the server timer as the main calculator.
The client will receive the time when the countdown begins:
var start = false; var startTime = 0; var myTime = new Date().getMilliseconds(); var delay = 1000 - myTime; setTimeout(function(){ intervalID = setInterval(function(){ myTime = new Date().getTime(); //console.log(myTime); to check if there is round number of milliseconds if (startTime <= myTime && start = true) {startCountdown();} }, 100); //put 1000 to check every second if second is round //or put 100 or 200 is second is not round }, delay); socket.on('data loaded', data){ startTime = data.time; start = true; } function startCountdown(){ //your time countdown }
And this works great when 2 clients are from the same region, so you will need a “time converter” to check if the time is good due to the time difference if you strictly need the same numbers.
After the countdown ends, you must clearInterval(intervalID);
Avoid
source share