Firebase onDisconnect when disconnecting WIFI

I noticed when I installed onDisconnect(), hit my application on another computer and turned off WIFI, my db is not updated; however it is updated when I turn on WIFI again. This bothers me because I'm building an application with the expected mobile users, and I want to gracefully handle temporary connection reductions.

On the other hand, /.info/connected knows about disconnecting and connecting immediately.

Can someone explain why this is happening, and if there is a way to prevent breaks after the connection is restored?

Updated code:

      var connectedRef, userRef;
      connectedRef = new Firebase('https://{fb}/.info/connected');
      userRef = new Firebase('https://{fb}/users/myUser');

      connectedRef.on('value', function (snap) {

        if (snap.val()) {
          userRef.update({ online: true });
          userRef.onDisconnect().update({ online: false }, function () {
            console.log('Turn the Wi-Fi off after seeing this log.');
          });
        }

      });

Result: . When I turn off Wi-Fi, db does not set to “on-line” unless I wait about 1 minute. When I turn on Wi-Fi again, db will set online to false.

+4
1

Wi-Fi . , , onDisconnect. , :

1) onDisconnect op ( onDisconnect)

2) , ( / (1 )

3) Firebase onDisconnect , ( , op )

, onDisconnect() , goOffline(), , , .

+5

Source: https://habr.com/ru/post/1548553/


All Articles