選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

consumers.py 1.2KB

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