You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

consumers.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # chat/consumers.py
  2. import json
  3. from channels.generic.websocket import WebsocketConsumer,AsyncWebsocketConsumer
  4. import wsps.tasks_loop
  5. import time
  6. p=print
  7. Mixins = wsps.tasks_loop.Mixins
  8. # class ChatConsumer(WebsocketConsumer,wsps.tasks_loop.AclTaskMixin,wsps.tasks_loop.AconMixin):
  9. class ChatConsumer(
  10. Mixins.AclTaskMixin,
  11. Mixins.AconMixin,
  12. AsyncWebsocketConsumer
  13. ):
  14. # def connect(self):
  15. async def ws_conn(self):
  16. p("!!!!!!!!!!!!!!!!!!!!?")
  17. print("",end="",flush=True)
  18. # time.sleep(1.5)
  19. # p("!!!!!!!!!!!!!!!!!!!!")
  20. # print("",end="",flush=True)
  21. self.accept()
  22. async def ws_disconn(self, close_code):
  23. pass
  24. async def ws_rec(self, text_data):
  25. p("text_data:",text_data)
  26. print("",end="",flush=True)
  27. text_data_json = json.loads(text_data)
  28. message = text_data_json['message']
  29. self.send(text_data=json.dumps({
  30. 'message': message
  31. }))
  32. self.send(text_data=json.dumps({
  33. 'zzz': {"abc":123}
  34. }))
  35. # print(">>>>>>>>>>>>>")
  36. print("++?",end="\n",flush=True)
  37. # print("++2?",end="\n",flush=True)
  38. # print("++",end="\n",flush=True)