I understand that in Firebase I can register my page for callbacks with the "on" method.
我知道在Firebase中我可以使用“on”方法注册我的页面以进行回调。
According to their docs:
根据他们的文件:
on( ) is used to listen for data changes at a particular location. This is the primary way to read data from Firebase.
on()用于侦听特定位置的数据更改。这是从Firebase读取数据的主要方式。
firebaseRef.on('value', function(dataSnapshot) {
// code to handle new value.
});
My question is:
我的问题是:
How does it work ?
它是如何工作的 ?
How does it know that something has changed on the serverside ?
它是如何知道服务器端的内容发生了变化的?
(better) How does the server can 'callback' the browser ?
(更好)服务器如何“回调”浏览器?
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文档或属性中没有看到有关此方法的参考资料来配置轮询时间...
Does anybody know ?
有人知道吗?
Many Thanks
非常感谢
1 个解决方案
#1
25
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.
Firebase使用WebSockets允许服务器将数据“推送”到客户端。由于并非所有浏览器版本都支持WebSockets,它也会回退到那些浏览器的长轮询。
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.
在服务器上如何工作的实现细节是专有的和复杂的 - 足以写一本关于SO问题范围的书。逻辑上,完全按照宣传的方式工作:服务的设计使得无论何时调用set(),push()或update()(或REST等价物),它都会通知任何侦听器更改。
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.
无论浏览器是否使用WebSockets,都没有“轮询时间”,因为客户端不会反复联系服务器。长轮询意味着等待数据发生更改,而不是反复轮询以查看是否发生了更改。正如您可以通过尝试教程或任何实时示例所看到的那样,数据更改会在几毫秒内同步到所有客户端 - 无需配置任何内容。
#1
25
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.
Firebase使用WebSockets允许服务器将数据“推送”到客户端。由于并非所有浏览器版本都支持WebSockets,它也会回退到那些浏览器的长轮询。
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.
在服务器上如何工作的实现细节是专有的和复杂的 - 足以写一本关于SO问题范围的书。逻辑上,完全按照宣传的方式工作:服务的设计使得无论何时调用set(),push()或update()(或REST等价物),它都会通知任何侦听器更改。
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.
无论浏览器是否使用WebSockets,都没有“轮询时间”,因为客户端不会反复联系服务器。长轮询意味着等待数据发生更改,而不是反复轮询以查看是否发生了更改。正如您可以通过尝试教程或任何实时示例所看到的那样,数据更改会在几毫秒内同步到所有客户端 - 无需配置任何内容。