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 968B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. # ???
  8. Mixins = wsps.tasks_loop.Mixins
  9. # class ChatConsumer(WebsocketConsumer,wsps.tasks_loop.AclTaskMixin,wsps.tasks_loop.AconMixin):
  10. class DispConsumer():
  11. async def ws_rec_once(self, text_data):
  12. # print("WS~~ 12")
  13. msg_data = json.loads(text_data)
  14. if "key" in msg_data:
  15. key = "jm_" + msg_data["key"]
  16. mthd = getattr(self,key,None)
  17. if mthd:
  18. await mthd(msg_data)
  19. else:
  20. p("METHOD " + key + " NOT FOUND!")
  21. print("",end="",flush=True)
  22. class ChatConsumer(
  23. DispConsumer,
  24. Mixins.DevMixin,
  25. Mixins.LoneMixinA,
  26. Mixins.AclTaskMixin,
  27. Mixins.AconMixin,
  28. Mixins.LoneMixinB,
  29. Mixins.DevMroMixin,
  30. AsyncWebsocketConsumer,
  31. ):
  32. async def ws_conn0(self):
  33. print("",end="",flush=True)
  34. self.accept()
  35. async def ws_disconn(self, close_code):
  36. pass
  37. Mixins.ChatConsumer = ChatConsumer