This commit is contained in:
chenyang
2022-06-29 16:28:42 +08:00
parent eac5f2eab7
commit 1eabd65d02
5 changed files with 27 additions and 10 deletions
+8 -2
View File
@@ -14,7 +14,9 @@ class QrConsumer(WebsocketConsumer):
def connect(self):
self.room_group_name = 'qr%s' % bytes.decode(self.scope['query_string'])
# print(self.room_group_name)
self.channel_name = 'qr_cn%s' % bytes.decode(self.scope['query_string'])
print(self.room_group_name)
print(self.channel_name)
# Join room group
async_to_sync(self.channel_layer.group_add)(
@@ -22,6 +24,7 @@ class QrConsumer(WebsocketConsumer):
self.channel_name
)
self.accept()
self.send(text_data=self.channel_name)
qrContext.add(self.channel_name, self)
def disconnect(self, close_code):
@@ -34,7 +37,7 @@ class QrConsumer(WebsocketConsumer):
print('close')
# Receive message from WebSocket
def receive(self, text_data):
def receive(self, text_data=None, bytes_data=None):
# Send message to room group
async_to_sync(self.channel_layer.group_send)(
self.room_group_name,
@@ -51,3 +54,6 @@ class QrConsumer(WebsocketConsumer):
# Send message to WebSocket
self.send(text_data=message)
def sed_text(self, text):
self.send(text_data=text)