Firebase回调-潜在的触发因素是什么? [英] Firebase Callbacks - what's the underlying trigger?

查看:73
本文介绍了Firebase回调-潜在的触发因素是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解在Firebase中,我可以使用"on"方法为回调注册我的页面.

I understand that in Firebase I can register my page for callbacks with the "on" method.

根据他们的文档:

on()用于侦听特定位置的数据更改. 这是从Firebase读取数据的主要方法.

on( ) is used to listen for data changes at a particular location. This is the primary way to read data from Firebase.

firebaseRef.on('value', function(dataSnapshot) {
  // code to handle new value.
});

我的问题是:

它如何工作?

它怎么知道服务器端发生了什么变化?

How does it know that something has changed on the serverside ?

(更好)服务器如何回调"浏览器?

(better) How does the server can 'callback' the browser ?

一个答案可能是它在轮询".但是在Firebase文档或配置轮询时间的属性中,我没有看到有关此方法的参考...

One answer might be that it is "polling". But I have seen no reference about this approach in Firebase documentation or properties to configure polling time ...

有人知道吗?

很多 谢谢

推荐答案

Firebase使用 WebSockets 来允许服务器向客户端"推送"数据.由于并非所有浏览器版本都支持WebSocket,因此对于这些浏览器,它还可以使用长时间轮询

Firebase uses WebSockets to allow the server to "push" data to the client. Since not all browser versions support WebSockets yet, it also falls back to long polling for those browsers.

如何在服务器上工作的实现细节是专有且复杂的-足以写一本关于SO问题的书籍,而且超出了SO问题的范围.从逻辑上讲,其工作方式与所宣传的完全相同:该服务的设计旨在使每当调用set(),push()或update()(或REST等效项)时,它都会将更改通知给所有侦听器.

The implementation details of how that works on the server are proprietary and sophisticated--enough to write a book about and beyond the scope of a SO question. Logically, works exactly as advertised: The service is designed so that any time a set(), push(), or update() is called (or the REST equivalents), it notifies any listeners of the change.

无论浏览器是否使用WebSockets,都没有轮询时间",因为客户端没有反复联系服务器.长轮询意味着等待数据更改发生,而不是反复轮询以查看是否发生了更改.如您所见,可以尝试本教程或任何实时示例,更改只需几毫秒即可同步到所有客户端,无需配置.

Regardless of whether the browser uses WebSockets or not, there is no "polling time" as the client is not repeatedly contacting the server. Long polling means waiting for a data change to occur, rather than polling repeatedly to see if a change has occurred. As you can see by trying out the tutorial or any of the real-time examples, data changes are synced to all clients in a matter of milliseconds--nothing to configure.

这篇关于Firebase回调-潜在的触发因素是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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