From bf1eb6c280115a3af463f0126ab41675e02d8eec Mon Sep 17 00:00:00 2001 From: Bill Schumacher Date: Tue, 5 Nov 2019 09:31:13 -0600 Subject: [PATCH] Fix for using external group send. --- daphne/__init__.py | 2 +- daphne/ws_protocol.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/daphne/__init__.py b/daphne/__init__.py index 55e4709..2e6c576 100755 --- a/daphne/__init__.py +++ b/daphne/__init__.py @@ -1 +1 @@ -__version__ = "2.3.0" +__version__ = "2.3.0a1" diff --git a/daphne/ws_protocol.py b/daphne/ws_protocol.py index 1962450..db574be 100755 --- a/daphne/ws_protocol.py +++ b/daphne/ws_protocol.py @@ -199,7 +199,15 @@ class WebSocketProtocol(WebSocketServerProtocol): if message.get("bytes", None): self.serverSend(message["bytes"], True) if message.get("text", None): - self.serverSend(message["text"], False) + # When sending a message using: + # async_to_sync(channel_layer.group_send)("group1", {"type": "send", "text": "data"}) + # The below is in error as a dictionary is passed through. But you need to format your request as a + # dictionary. + # Maybe there's a better way to fix this. + if type(message.get("text")) == dict: + self.serverSend(message["text"]["text"], False) + else: + self.serverSend(message["text"], False) def handle_exception(self, exception): """