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

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