chat
chat copied to clipboard
How to handle client closed event?
It seems that the redis connection keeped when the page is closed. How to handle client closed event ?
Hey Yishh, did you find a solution for the issue? I'm having the same problem!
This should be possible using a closeable iterator: lift the generator in the __iter__
method of an object (can just convert event_stream
to a class) and add a close
method, which will be called on connection close.
However, this may only happen when a write to the socket fails, so there probably needs to be a "heartbeat" regularly sending something irrelevant (e.g. a line of comment) in order to trigger the failure, and thus the closing of the iterator.
As far as I can see, for the current redis-based implementation this would require a timeout on pubsub.listen()
, which I don't believe exists.
Here's a zmq conversion demonstrating it: https://github.com/masklinn/chat/blob/zmq/app.py