Fixed #244: .close() on Websocket generic consumers

This commit is contained in:
Andrew Godwin 2016-07-13 17:19:39 -07:00
parent 27d064328a
commit af606ff895
2 changed files with 9 additions and 0 deletions

View File

@ -106,6 +106,12 @@ class WebsocketConsumer(BaseConsumer):
else:
raise ValueError("You must pass text or bytes")
def close(self):
"""
Closes the WebSocket from the server end
"""
self.message.reply_channel.send({"close": True})
def raw_disconnect(self, message, **kwargs):
"""
Called when a WebSocket connection is closed. Base level so you don't

View File

@ -172,6 +172,9 @@ Note that this subclass still can't intercept ``Group.send()`` calls to make
them into JSON automatically, but it does provide ``self.group_send(name, content)``
that will do this for you if you call it explicitly.
``self.close()`` is also provided to easily close the WebSocket from the server
end once you are done with it.
Sessions and Users
------------------