Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

consumers.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 'message' in text_data_json:
  14. if "key" in msg_data:
  15. key = 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. # def connect(self):
  33. async def ws_conn(self):
  34. p("!!!!!!!!!!!!!!!!!!!!?")
  35. print("",end="",flush=True)
  36. # time.sleep(1.5)
  37. # p("!!!!!!!!!!!!!!!!!!!!")
  38. # print("",end="",flush=True)
  39. self.accept()
  40. await self.send(text_data=json.dumps({
  41. 'wsconn': {"abc.":123}
  42. }))
  43. async def ws_disconn(self, close_code):
  44. pass
  45. async def ws_disconn_z(self, close_code):
  46. pass
  47. async def ws_rec(self, text_data):
  48. return
  49. p("text_data:",text_data)
  50. print("",end="",flush=True)
  51. text_data_json = json.loads(text_data)
  52. message = text_data_json['message']
  53. await self.send(text_data=json.dumps({
  54. 'message': message
  55. }))
  56. await self.send(text_data=json.dumps({
  57. 'zzz': {"abc":123}
  58. }))
  59. # print(">>>>>>>>>>>>>")
  60. Mixins.ChatConsumer = ChatConsumer
  61. print("++?",end="\n",flush=True)
  62. # print("++2?",end="\n",flush=True)
  63. # print("++",end="\n",flush=True)