Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if user is online for a chat app made using Firebase

Using Real Time Database of Firebase to create a Chat App.

The users class looks like this (default is JSON in Firebase)

"users" : {
     "-K2ib62mjHh34CAUfig" : {
      "lastvisibleat" : "2016-09-30 07:10:40",
      "name" : "Peter Parker",
      "online" : "1"
    },
    "--K2ib62mjHh34CAUh18" : {
      "lastvisibleat" : "2016-09-30 07:26:17",
      "name" : "Riddhi Dixit",
      "online" : "1"
    }
}

I want to change the status from online: "1" to online : "0" when the user's internet suddenly gets unavailable or browser crashes of its own or something as such that cannot be handled with sess_destroy() method of CodeIgniter.

Server is build in PHP using CodeIgniter.

like image 292
prashant0205 Avatar asked Nov 14 '25 19:11

prashant0205


1 Answers

I recommend using Firebase's built-in onDisconnect() hook. It enables you to predefine an operation that will happen as soon as the client becomes disconnected.

See Firebase documentation: Managing presence for Web clients.

The linked document targets web clients, but equivalent functionality is available for Android and iOS clients too.

like image 54
Martin Öjes Avatar answered Nov 17 '25 07:11

Martin Öjes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!