I've a simple code which set offline for the user in my sql database.
Server
io.on('connection', function (socket) { ApiHelper.setUserOnline(socket.token); socket.on('disconnect', function () { ApiHelper.setUserOffline(socket.token); }); } So lets say,
An user connect to socket than he lost the network connection then reconnect.
I get this logs.
- User connected (he is online)
- Network losted.
- Network losted but disconnect event has not received by server yet, so user is still online
- User reconnect to network and then socket. User is still online.
- Previous disconnect event recevied by server and user is set offline in database. But wait user has just reconnect so actually user must be online.
Because of disconnect event fired late we saw the user is offline in database.
How can I achieve this problem?