Striving to become a master Go/Cloud developer; Father ๐จโ๐งโ๐ฆ; ๐ค/((Full Stack Web|Unity3D) + Developer)/g; Science supporter ๐ฉโ๐ฌ; https://coder.today
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.
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.
Striving to become a master Go/Cloud developer; Father ๐จโ๐งโ๐ฆ; ๐ค/((Full Stack Web|Unity3D) + Developer)/g; Science supporter ๐ฉโ๐ฌ; https://coder.today
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.
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.
I stumbled upon a video that treat all 3 subjects and I remembered this topic:
youtu.be/GX4595KeZyc