Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- consumers.py
- class NotificationConsumer(WebsocketConsumer):
- def connect(self):
- if self.scope["user"].is_anonymous:
- self.close()
- else:
- self.group_name = "user_id_" + str(self.scope["user"].id)
- async_to_sync(self.channel_layer.group_add)(
- self.group_name, self.channel_name
- )
- self.accept()
- def disconnect(self, close_code):
- self.close()
- def notify(self, event):
- self.send(text_data=json.dumps(event["text"]))
Advertisement
Add Comment
Please, Sign In to add comment