I'm using emit method to start a countdown on my android app.
My problem is that the countdown doesn't start at the same time for the player and opponent. My game will play a random song and give points to the first player who guesses correct
I heard that it depends on their latency. I couldn't find any solution to solve this.
var countdown = 3;
var countdownInterval = setInterval(function () {
socket.emit('countdown', countdown); // to player
socket.broadcast.to(opponent).emit('countdown', countdown); // to opponent
if (countdown == 0) {
clearInterval(countdownInterval);
}
countdown--;
}, 1000);