Manage online offline status
See original GitHub issueIs it possible to use the onDisconnect feature described on this website?
https://firebase.google.com/docs/database/web/offline-capabilities
// any time that connectionsRef's value is null (i.e. has no children) I am offline
var myConnectionsRef = firebase.database().ref('users/joe/connections');
// stores the timestamp of my last disconnect (the last time I was seen online)
var lastOnlineRef = firebase.database().ref('users/joe/lastOnline');
var connectedRef = firebase.database().ref('.info/connected');
connectedRef.on('value', function(snap) {
if (snap.val() === true) {
// We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect)
var con = myConnectionsRef.push();
// When I disconnect, remove this device
con.onDisconnect().remove();
// Add this device to my connections list
// this value could contain info about the device or a timestamp too
con.set(true);
// When I disconnect, update the last time I was seen online
lastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP);
}
});```
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Handle users' online and offline status in Firebase
I want to handle the online and offline status in my webapp. So that users can see who is online and who not....
Read more >Determine Realtime User Online/Offline Status Using Socket.io
In this video you will be able to integrate socket & determine user status. If a user is logged in then it will...
Read more >Detecting If a User is Online/Offline with JavaScript - DEV ...
In this post, we are going to look at a super-easy way to check if the user is connected to the internet and...
Read more >How smart things manage the online/offline status
When we set the power control to off the device such as Light/ TV still returns the online status and we can turn...
Read more >Detecting Online/Offline Status in Javascript - Level Up Coding
We can detect if the user is online or offline by using the online property on the navigator object which will return true...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is how I’m using it, is this what you’re looking for?
Although if you’re trying to build a presence system, you might want to look at this link, as what you can do in the offline callback is limited (as you’re offline): https://firebase.googleblog.com/2013/06/how-to-build-presence-system.html
Indeed it isn’t a function because it’s not currently implemented (nor documented).