1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- # chat/consumers.py
- import json
- from channels.generic.websocket import WebsocketConsumer,AsyncWebsocketConsumer
- import wsps.tasks_loop
- import time
- p=print
-
- Mixins = wsps.tasks_loop.Mixins
-
-
- # class ChatConsumer(WebsocketConsumer,wsps.tasks_loop.AclTaskMixin,wsps.tasks_loop.AconMixin):
- class DispConsumer():
- async def ws_rec_once(self, text_data):
- print("WS~~ 12")
- msg_data = json.loads(text_data)
- # if 'message' in text_data_json:
-
- if "key" in msg_data:
- key = "_" + msg_data["key"]
- mthd = getattr(self,key,None)
- if mthd:
- await mthd(msg_data)
- else:
- p("METHOD " + key + " NOT FOUND!")
- print("",end="",flush=True)
-
-
-
-
- class ChatConsumer(
- DispConsumer,
- Mixins.DevMixin,
- Mixins.LoneMixinA,
- Mixins.AclTaskMixin,
- Mixins.AconMixin,
- Mixins.LoneMixinB,
- Mixins.DevMroMixin,
- AsyncWebsocketConsumer,
- ):
- # def connect(self):
- async def ws_conn0(self):
- print("ChatConsumer:ws_conn0")
- # p("!!!!!!!!!!!!!!!!!!!!?")
- print("",end="",flush=True)
- # time.sleep(1.5)
-
- # p("!!!!!!!!!!!!!!!!!!!!")
- # print("",end="",flush=True)
- self.accept()
-
-
- await self.send(text_data=json.dumps({
- 'wsconn': {"abc.":123}
- }))
-
-
- async def ws_disconn(self, close_code):
- pass
-
- async def ws_disconn_z(self, close_code):
- pass
-
- async def ws_rec(self, text_data):
- return
- p("text_data:",text_data)
- print("",end="",flush=True)
- text_data_json = json.loads(text_data)
- message = text_data_json['message']
-
- await self.send(text_data=json.dumps({
- 'message': message
- }))
-
-
- await self.send(text_data=json.dumps({
- 'zzz': {"abc":123}
- }))
-
-
- # print(">>>>>>>>>>>>>")
- Mixins.ChatConsumer = ChatConsumer
-
- print("++?",end="\n",flush=True)
- # print("++2?",end="\n",flush=True)
-
- # print("++",end="\n",flush=True)
|