无延迟的Firebase事件 [英] Firebase events with no delay

查看:85
本文介绍了无延迟的Firebase事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Firebase事件 api是个好主意吗?在客户端之间实时同步某些东西?

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

例如,如果我想完全同时在客户端上播放视频(延迟少于30ms),我可以在这里依靠Firebase吗?有什么方法可以使用Firebase尽可能在两个客户端上启动同步的事件? (假设客户端在浏览器中查看的是同一页面).

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.

另一种方法是交换数据包:从XXX UTC开始",其中XXX是现在的时间+ 1000ms(例如).对于一个客户端,数据包传输可能需要40毫秒,而对于另外900毫秒.但是此事件将被同步.但是这里的问题是如何知道客户时间设置正确?

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.

推荐答案

当客户端连接到Firebase数据库后端时,Firebase SDK会检测到该客户端的延迟.对于检测到的延迟,将自动更正基于本地时间的操作(例如push()ServerValue.TIMESTAMP).您也可以.info/serverTimeOffset 上的延迟

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.

由此,您可以获得Firebase对客户端同步程度的最佳估计.任何人都猜测这是否足以使视频播放同步以满足您的需求.不过,如果您开始进行测试,我希望能听到一些数字.

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.

这篇关于无延迟的Firebase事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆