0

I am building a web app using Vue and Socket.io. The app is divided into two: A Host (Hosting a party) and the guests. It's a party game and the people participating will be guidede to do stuff simultaneously so syncing between devices is crucial. Every body (including the host) will be asked to download an audio file. Once everybody has downloaded the audio file the Host can then start the playback on all devices using socket.io. The Host emits an event "startAllAudio" to the socket.

socket.emit("startAllAudio");

When the socket gets the event it emits a new event "startAudio" with a timestamp set 3 seconds ahead in time.

const startDelay = 3000;
var now = new Date().getTime();
io.emit("startAudio", {
      timeToStart: now + parseInt(startDelay),
});

All this works like a charm on iOs devices. But on android it does not. After debugging a lot I found that the internal clock on the Android devices is out of sync with (Or at least not the same as) the iOs devices. I have two different relatively new Android phones for testing and even they are not in sync with each other. I have 10+ various iOs devices for testing and the all sync perfectly.

I made a javascript clock with milliseconds and put it on the web app for debugging. And you can clearly see that the two Android phones are different from each other and from the iOs devices which are the same (within reason). The difference in time matches the audible difference in playback.

var interval = window.setInterval(() => {
      const date = new Date(Date.now());
      this.time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + ":" + date.getMilliseconds();
}, 500);

So finally we get to the actual question(s): How would you go about fixing that? Can you force the android devices to timesync? Maybe even to a specific time server? I thought about "probing" the responce time between the web app and the socket. i.e. sending 3 emits and time the respons time and the take an average of that and use it with the timestamp on the Android phones to adjust the timeToStart value sendt from the socket. But it does not seem like a bulletproof method. Any suggestions would be greatly appreciated.

  • Did you tried to get time with Calendar on Android ? – Ptit Xav Oct 22 '22 at 08:18
  • Hey Ptit I am not sure how to do that. Can you do that from the browser with javascript? – Van den Sohn Oct 23 '22 at 10:25
  • Sorry I misread your post. BTW, did you tried to switch off and on the automatic date time settings on the Android phone ? Seems to reset correct time synchronisation. – Ptit Xav Oct 23 '22 at 14:34
  • [this](https://stackoverflow.com/questions/20269657/right-way-to-get-web-server-time-and-display-it-on-web-pages) may also help you to get a common time reference from you web server. – Ptit Xav Oct 23 '22 at 14:36

0 Answers0