Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

consumers.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. class DevRlist(*wsps.tasks_loop.eclass_factory(10)):pass
  38. # eclass_factory
  39. Mixins.DevRlist = DevRlist
  40. class RoomListConsumer(
  41. # Mixins.DevMixin,
  42. # Mixins.LoneMixinA,
  43. # Mixins.LoneMixinB,
  44. # Mixins.DevMroMixin,
  45. DispConsumer,
  46. Mixins.DevRlist,
  47. Mixins.AclTaskMixin,
  48. Mixins.AconMixin,
  49. AsyncWebsocketConsumer,
  50. ):
  51. async def ws_conn0(self):
  52. print("",end="",flush=True)
  53. self.accept()
  54. async def ws_disconn(self, close_code):
  55. pass
  56. Mixins.RoomListConsumer = RoomListConsumer
  57. Mixins.ChatConsumer = ChatConsumer