russellxu's avatar

Can Reverb get user online/offline status in backend?

I'm building a web game based on Websocket, I need to know which user is online or offline in realtime.

I googled a little, and I found out it has to be the client-side to told server-side if user is online or offline. such as:

Echo.join('').here(e => {
	//ajax request to told server this user is online
}).leaving(e => {
	//ajax request to told server this user is offline
})

Howerver there is one problem: If user disconnected accidently without trigger the leaving hook. Such as user's web browser crashed. Server-side may not know about user's offline status.

Maybe I can pull-in some heartbeat strategy, but I think there must be some better way to do this.

I notice that Echo is sending and retriving ping-pong messages. It's that mean Reverb is already detecting if user is offline?

If I can just get all online users list and listen to user's leaving event in server-side. then I can updating user status without involing client-side and reduce http requests.

So what is the best practice for doing this?

0 likes
0 replies

Please or to participate in this conversation.