Python channels.generic.websocket.WebsocketConsumer() Examples

The following are 1 code examples of channels.generic.websocket.WebsocketConsumer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module channels.generic.websocket , or try the search function .
Example #1
Source File: consumers.py    From chain with Apache License 2.0 5 votes vote down vote up
def disconnect(self, close_code):
        async_to_sync(self.channel_layer.group_discard)(self.scope['user'].username, self.channel_name)


# class StatsConsumer(WebsocketConsumer):
#
#     def connect(self):
#         async_to_sync(self.channel_layer.group_add)(self.scope['user'].username, self.channel_name)
#
#         self.accept()
#
#     def receive(self, text_data):
#         key = '-'.join(('django-mstats-processlist', str(self.scope['user'].uid)))
#         cache.set(key, 'start', timeout=None)
#         show_processlist.delay(host=text_data, user=self.scope['user'].username, key=key)
#
#         async_to_sync(self.channel_layer.group_send)(
#             self.scope['user'].username,
#             {
#                 "type": "user.message",
#                 "text": text_data,
#             },
#         )
#
#     def user_message(self, event):
#         self.send(text_data=event["text"])
#
#     def disconnect(self, close_code):
#         key = '-'.join(('django-mstats-processlist', str(self.scope['user'].uid)))
#         cache.set(key, 'end', timeout=None)
#         async_to_sync(self.channel_layer.group_discard)(self.scope['user'].username, self.channel_name)