Firebase Callbacks - what's the underlying trigger?

前端 未结 1 1233
忘掉有多难
忘掉有多难 2021-02-05 10:24

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

According to their docs:

on( ) is used to listen for

1条回答
  •  深忆病人
    2021-02-05 11:05

    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.

    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.

    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.

    0 讨论(0)
提交回复
热议问题