django-websocket-redis
django-websocket-redis copied to clipboard
Is there any way to retrieve the connected users?
How can i retrieve all the users connected to the server? I need to check if user is online to choose the appropriate behavior
Currently not.
But this feature could be added and it makes sense. I would do it, so that Redis keeps a list of currently connected users. Then the Django loop can check if a users is in that list.
However, I think you can do that reliably only through the clients send_heartbeat
. This means that you would add that user to a Redis bucket, which times out after say 60 seconds. Whenever a heartbeat message is received from the client, this timer is reseted.
Before implementing this, I'd like to ask you, how quickly you need that information. If its >3*heartbeat_interval, then I would say yes. If you need it immediately, then its unreliable.
This will be a nice approach, but if there was an way to get the user on the request while the socket connect/disconnect would be easier to handle this
Whenever he connects yes, but ws4redis does not see reliably whenever he disconnects. If he really closes the browser window, then the connection is closed in a clean way. But if the browser looses TCP/IP connectivity, then that connection remains open. Therefore you can't reliably say, whenever a users disconnected - you can only say that you missed some heartbeat messages and therefore you assume he is not online anymore.
I did with the client send_heartbeat, whenever a heartbeat message is received from the client, the server updates the client last_seen field, with this i consider user online if last_seen time is 5 seconds less than actual time, the only problem i'm sending heartbeat through http, i'd like to send it over websocket, but i don't found way to receive the websocket message event inside django loop
@YuriHeupa You can hack into the code here: https://github.com/jrief/django-websocket-redis/blob/master/ws4redis/redis_store.py#L68
I jump from there back to my django code and do the black magic. (Attention: Keep in mind, no blocking operations or you do monkey patching!)
I think there should be an option like WS4REDIS_ALLOWED_CHANNELS which can be used for heartbeat operations.
+1
Can someone pls help with this issue? I am unable to figure out how to implement it. Thanks.