Roman Pushkin
Roman Pushkin

Reputation: 6079

Firebase events with no delay

Is it a good idea to use Firebase events api to sync something between clients in real time?

For example, if I want to play video on clients exactly at the same time (with delays less than 30ms), can I rely on Firebase here? Is there any way to use Firebase to start events synced as much as it possible on both clients? (assuming clients are looking at the same page in the browser).

I tried to play with it, and it seems pretty reliable, but I'm not sure it is the right approach.

Another way of doing that is just to exchange the packet saying: "Starting at XXX UTC", where XXX is the time of now + 1000ms (for example). For one client packet transmission can take 40ms, for another 900ms. But this event will be synced. But the question here is how to know that client time is set up correctly?

I don't want to reinvent the wheel, and wanna check if you guys had this experience before.

Upvotes: 6

Views: 2203

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599581

When a client connects to the Firebase Database back-end, the Firebase SDK detects the latency of that client. Local time-based operations (such as push() and ServerValue.TIMESTAMP) are automatically corrected for that detected latency. You can also listen for the latency on .info/serverTimeOffset.

With that you can get Firebase's best estimate of how in-sync the clients are. Whether that is enough to synchronize video playback for your needs is anyone's guess. I'd love to hear some numbers if you start testing it though.

Upvotes: 5

Related Questions