Mark users as online or offline.
Currently we need to hook into the socket to mark as user online when:
- They connect & authenticate
and offline when:
- When the socket disconnects
- When they logout
- When they haven't been authenticated or done anything for a while (ie. token expires maybe?)
Is there a way, when they authenticate, to get the socket id on which it has happened ? This way, we could have an array of socket id on which the user is currently connected (and if the array is empty, then the user isn't connected anywhere).
Marshall mentioned that feather-authenticate v1 now has auth.on('create', ...) and auth.on('remove', ...)?
It has app.on('login') and app.on('logout') (which emits some additional information like the connection and request/response object if available).
@daffl app.on('logout') seems to not be generating for rest provider. app.on('login') seems to be generating for both socket io and rest
For REST the user has to explicitly call app.logout() since there is no other way to tell. In Socket.io the logout event will also be sent on socket disconnection.
Could someone please paste the code needed to hack into socket.io for listing all user connections?
The best (and not so hacky) way to get all connections is to combine all event channels and list those connections:
app.channel(app.channels).connections.forEach(connection => {});