Firebase-js-sdk: .info/connected and ondisconnect() does not work when device offline

Created on 14 Jan 2018  路  4Comments  路  Source: firebase/firebase-js-sdk

I am using this is node.js firebase client, whenever i run the script it works fine but as i disconnect my wifi this function is not called also there is no change in the database for disconnect event.
Is there any other method which i can use to detect firebase connection other this method.

var connectedRef = firebase.database().ref('.info/connected');
connectedRef.on('value', function(snap) {
if (snap.val() === true) {
onlinestatus = true;
myConnectionsRef.onDisconnect().set(false);
myConnectionsRef.set(true);
lastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP);
}else{
onlinestatus = false;
console.log("network issue");
}

database

Most helpful comment

Experiencing the same issue. There are definitely a bunch of active listeners but still... the database connectivity check via .info/connected is very unreliable unfortunately.

All 4 comments

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

The Firebase RTDB SDK will only open a network connection when there are either outstanding writes or active listeners. To use .info/connected properly, you need to have a listener enabled. .info/connected is not meant to convey that your device's connectivity, but rather reports the connectivity status of the SDK itself.

Experiencing the same issue. There are definitely a bunch of active listeners but still... the database connectivity check via .info/connected is very unreliable unfortunately.

Was this page helpful?
0 / 5 - 0 ratings