I want to disconnect a firebase socket without refreshing or closing the page, but how to do that?
Is there any method like socket.disconnect() or socket.close() I can use? I have just found the socket.onDisconnect() method.
I want to disconnect a firebase socket without refreshing or closing the page, but how to do that?
Is there any method like socket.disconnect() or socket.close() I can use? I have just found the socket.onDisconnect() method.
Firebase recently added support for two new static methods to each client, Firebase.goOffline()
and Firebase.goOnline()
, which allow you to manually disconnect and reconnect in your application.
From 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.
See Firebase.goOffline( ) and Firebase.goOnline( ) for more details.
var dataRef = new Firebase("https://SampleChat.firebaseio-demo.com/");
You can disconnect using dataRef.unauth().