From 63c834bf5f592ffe122e34d79f8c840d9b05aaa2 Mon Sep 17 00:00:00 2001 From: Jaehun You Date: Thu, 21 Nov 2024 15:23:40 +0900 Subject: [PATCH] Add channel to group when connecting See also: #17 --- wlm_server/operation/consumers.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 wlm_server/operation/consumers.py diff --git a/wlm_server/operation/consumers.py b/wlm_server/operation/consumers.py new file mode 100644 index 0000000..5ee4c61 --- /dev/null +++ b/wlm_server/operation/consumers.py @@ -0,0 +1,16 @@ +from channels.generic.websocket import AsyncWebsocketConsumer + +class OperationConsumer(AsyncWebsocketConsumer): + """Consumer for notifying the operation change of a specific channel. + + Attributes: + ch: Target WLM channel. + group_name: Name of group it belongs to in the channel layer. + """ + + # pylint: disable=attribute-defined-outside-init + async def connect(self): + self.ch = self.scope['url_route']['kwargs']['ch'] + self.group_name = f'channel_{self.ch}' + await self.channel_layer.group_add(self.group_name, self.channel_name) + await self.accept()