gpt4 book ai didi

firebase - 在不刷新或关闭页面的情况下断开 Firebase 套接字

转载 作者:行者123 更新时间:2023-12-04 08:56:22 25 4
gpt4 key购买 nike

我想在不刷新或关闭页面的情况下断开 Firebase 套接字的连接,但是怎么做呢?

有没有像 socket.disconnect() 或 socket.close() 这样的方法我可以使用?我刚刚找到了 socket.onDisconnect() 方法。

最佳答案

Firebase 最近为每个客户端添加了对两个新静态方法的支持,Firebase.goOffline()Firebase.goOnline() ,它允许您在应用程序中手动断开连接并重新连接。

来自 https://www.firebase.com/docs/javascript/firebase/gooffline.html :

Manually disconnect the Firebase client from the server and disable automatic reconnection.

The Firebase client automatically maintains a persistent connection to the Firebase server, which will remain active indefinitely and reconnect when disconnected. However, the goOffline( ) and goOnline( ) methods may be used to manually control the client connection in cases where a persistent connection is undesirable.

While offline, the Firebase client will no longer receive data updates from the server. However, all Firebase operations performed locally will continue to immediately fire events, allowing your application to continue behaving normally. Additionally, each operation performed locally will automatically be queued and retried upon reconnection to the Firebase server.

To reconnect to the Firebase server and begin receiving remote events, see goOnline( ). Once the connection is reestablished, the Firebase client will transmit the appropriate data and fire the appropriate events so that your client "catches up" automatically.

Note: Invoking this method will impact all Firebase connections.



Firebase.goOffline( )Firebase.goOnline( )更多细节。

关于firebase - 在不刷新或关闭页面的情况下断开 Firebase 套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16493489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com