From 46d127758aa6ca80f0c2f726af6784a284ff2d29 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 1 Sep 2023 10:16:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20roomconsumer=20bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ws/consumers.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/ws/consumers.py b/apps/ws/consumers.py index cc34f5fd..75788a7a 100644 --- a/apps/ws/consumers.py +++ b/apps/ws/consumers.py @@ -31,14 +31,16 @@ class RoomConsumer(AsyncWebsocketConsumer): self.channel_name ) - async def receive_json(self, content, **kwargs): + async def receive(self, text_data=None, bytes_data=None): sender_user = self.scope["user"] - if content['type'] == 'chat': - content['from'] = sender_user.username - await self.channel_layer.group_send( - self.room_group_name, - content - ) + if text_data: + content = json.loads(text_data) + if content['type'] == 'chat': + content['from'] = sender_user.username + await self.channel_layer.group_send( + self.room_group_name, + content + ) async def chat(self, content): await self.send(json.dumps(content, ensure_ascii=False))