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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.DevMixin,
  11. Mixins.LoneMixinA,
  12. Mixins.AclTaskMixin,
  13. Mixins.AconMixin,
  14. AsyncWebsocketConsumer
  15. Mixins.LoneMixinB,
  16. Mixins.DevMroMixin,
  17. ):
  18. # def connect(self):
  19. async def ws_conn(self):
  20. p("!!!!!!!!!!!!!!!!!!!!?")
  21. print("",end="",flush=True)
  22. # time.sleep(1.5)
  23. # p("!!!!!!!!!!!!!!!!!!!!")
  24. # print("",end="",flush=True)
  25. self.accept()
  26. async def ws_disconn(self, close_code):
  27. pass
  28. async def ws_rec(self, text_data):
  29. p("text_data:",text_data)
  30. print("",end="",flush=True)
  31. text_data_json = json.loads(text_data)
  32. message = text_data_json['message']
  33. self.send(text_data=json.dumps({
  34. 'message': message
  35. }))
  36. self.send(text_data=json.dumps({
  37. 'zzz': {"abc":123}
  38. }))
  39. # print(">>>>>>>>>>>>>")
  40. print("++?",end="\n",flush=True)
  41. # print("++2?",end="\n",flush=True)
  42. # print("++",end="\n",flush=True)