本文整理匯總了Python中channels.generic.websocket.WebsocketConsumer方法的典型用法代碼示例。如果您正苦於以下問題:Python websocket.WebsocketConsumer方法的具體用法?Python websocket.WebsocketConsumer怎麽用?Python websocket.WebsocketConsumer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類channels.generic.websocket
的用法示例。
在下文中一共展示了websocket.WebsocketConsumer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: disconnect
# 需要導入模塊: from channels.generic import websocket [as 別名]
# 或者: from channels.generic.websocket import WebsocketConsumer [as 別名]
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)