DEV Community

Discussion on: Sports draft app: How to consistently broadcast timer to multiple clients?

Collapse
 
bgadrian profile image
Adrian B.G.

Welcome to the distributed systems and time hell!

You may want to check how real-time multiplayer games solve these problems, there are more approaches. You already have a start (the server is the source of truth) now you just need to sync the clients.

One issue may be if you use JS timers/timeouts, if the tab doesn't have the focus the ticks will be in slow mode. You can use workers (I think) and read the local time to improve the accuracy.

One way would be a mix between server signals, server time and user local time.

If you know in advance at what time a specific players turn can begin (even 1 minute should work) you can send it beforehand, and his client can begin its phase based on its local timer.

Even if the connection is slow its PC time should work ok and the player should see that is his turn. If the command arrives at the server and is not its actual turn ofc the server will reject it.

Bottom line 1 minute could be a too small time window if the users/game is casual, or 1 second sync times too big.

Collapse
 
allison_seboldt profile image
Allison Seboldt

Interesting idea using the PC time. I was thinking I need to adopt some multiplayer game techniques but I don't know the first thing about video game development. Will look into it.

Collapse
 
bgadrian profile image
Adrian B.G.

I stumbled upon a video that treat all 3 subjects and I remembered this topic:

youtu.be/GX4595KeZyc