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.

i1.py 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. class DevMixin_R1():
  2. async def az_call(self, *a,**kw):
  3. await asyncio.sleep(0.001)
  4. p("az_call:")
  5. p(end="",flush=True)
  6. async def ws_conn(self, *a,**kw):
  7. if not getattr(glob_cl,"z",None):
  8. glob_cl.z=self
  9. # p("????????????")
  10. await glob_cl.dev_group_add("chat_group_t1.all",self)
  11. # TODO:JFI group name needs a namespace to prevent collisions
  12. self.group_name= self.scope["url_route"]["kwargs"]["room_name"]
  13. # await glob_cl.dev_group_add("chat_group_t1.:all",self)
  14. await glob_cl.dev_group_add(self.group_name,self)
  15. async def con_ping0(self, text_data):
  16. p("con_ping0:")
  17. p(end="",flush=True)
  18. async def con_ping(self, text_data):
  19. # p("con_ping:",text_data)
  20. p("con_ping:")
  21. p(end="",flush=True)
  22. # p("!!!.?",flush=True)
  23. # p(flush=True)
  24. p(end="",flush=True)
  25. async def jm_group_size(self, text_data):
  26. await self.channel_layer.group_send(self.group_name,{"type":"con_ping","return_addr":self.channel_name})
  27. p("????????\n")
  28. asyncio.ensure_future(self.az_call())
  29. # glob_cl.loop.create_task(self.az_call())
  30. # glob_cl.loop.ensure_future(self.az_call())
  31. p(end="",flush=True)
  32. # return
  33. # await asyncio.sleep(0.001)
  34. p("!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
  35. p(end="",flush=True)
  36. async def jsto_send(self, text_data):
  37. p("jsto_send:",type(text_data))
  38. p(text_data)
  39. await self.send(text_data = json.dumps(text_data))
  40. async def jsend(self, text_data):
  41. p("jsend:",type(text_data))
  42. p(text_data)
  43. await self.send(text_data = json.dumps(text_data["payload"]))
  44. async def jm_group_sto_message(self, text_data):
  45. await self.channel_layer.group_send(self.group_name,{"payload":text_data,"type":"jsto_send"})
  46. async def jm_group_message(self, text_data):
  47. await self.channel_layer.group_send(self.group_name,{"payload":text_data,"type":"jsend"})
  48. async def jm_mtypex(self, text_data):
  49. p(self.groups)
  50. # p("abc")
  51. await self.send(text_data=json.dumps({
  52. "type":"z",
  53. 'm1': {"abc.":123}
  54. }))
  55. # await self.channel_layer.group_send("group1",self.channel_name)
  56. await self.channel_layer.group_send(self.group_name,{"zz":"HI...","type":"zz"})
  57. await self.channel_layer.send(self.channel_name,{"zz":"HI","type":"zz"})
  58. async def zz(self, text_data):
  59. p("HELO>???",text_data)
  60. class DevMixin_R2_DevSto():
  61. async def ws_conn(self, *a,**kw):
  62. self.group_count = 0
  63. # r'''
  64. await self.get_group_size({
  65. "CLIENT_KEY": "ws_sto",
  66. "group_count": -1,
  67. "sto_event_type": "group_count",
  68. "ws_conn":"???",
  69. })
  70. # '''
  71. # r'''
  72. await self.send(text_data = json.dumps({
  73. "CLIENT_KEY":"ws_sto",
  74. "sto_event_type": "connection_info",
  75. "channel_name":self.channel_name,
  76. "group_name":self.group_name,
  77. }))
  78. # '''
  79. async def ws_disconn(self, close_code):
  80. # TODO:JFI maybe call jm_tmp_dev_sto?
  81. await self.channel_layer.group_send(self.group_name,{"type":"jm_tmp_dev_sto_rec","from":self.channel_name,
  82. "CLIENT_KEY":"ws_sto",
  83. "sto_event_type": "user_disconnected",
  84. "group_name":self.group_name,
  85. "channel_name":self.channel_name,
  86. })
  87. # r'''
  88. # '''
  89. r'''
  90. await self.send(text_data=json.dumps({
  91. "sto_event_type": "user_disconnected",
  92. "channel_name":self.channel_name,
  93. "group_name":self.group_name,
  94. }))
  95. # '''
  96. async def group_size_count(self,*a,**kw):
  97. # await asyncio.sleep(0.1)
  98. # p("method/fn:",inspect.stack()[0][3])
  99. self.gc_t_fin =time.time()
  100. # await self.send(text_data=json.dumps({"CLIENT_KEY":"ws_sto","group_count":self.group_count,"sto_event_type":"group_count","t_fin":self.gc_t_fin,"t_0":self.gc_t_0,"t_arr":self.gc_t_arr}))
  101. # await self.send(text_data=json.dumps({"CLIENT_KEY":"ws_sto","group_count":self.group_count,"sto_event_type":"group_count","tx":time_difs(self.gc_t_0,self.gc_t_fin,self.gc_t_arr)}))
  102. await self.send(text_data=json.dumps({"CLIENT_KEY":"ws_sto","group_count":self.group_count,"sto_event_type":"group_count"}))
  103. pass
  104. async def group_size_pong(self,text_data):
  105. self.group_count += 1
  106. self.gc_t_arr.append(time.time())
  107. async def group_size_ping(self,text_data):
  108. await self.channel_layer.send(text_data["from"],{"type":"group_size_pong","from":self.channel_name})
  109. # p("group_size_ping")
  110. async def jm_get_group_size(self,text_data):
  111. await self.get_group_size(text_data)
  112. async def get_group_size(self,text_data):
  113. self.group_count = 0
  114. self.gc_t_0=time.time()
  115. self.gc_t_arr=[]
  116. # p(self.gc_ts1)
  117. await self.channel_layer.group_send(self.group_name,{"type":"group_size_ping","from":self.channel_name})
  118. glob_cl.cbs_asap.append(self.group_size_count)
  119. async def jm_tmp_dev_sto_rec(self,text_data):
  120. _from = text_data.get("from")
  121. pass
  122. if (_from == self.channel_name):
  123. await self.send(text_data = json.dumps(text_data))
  124. pass
  125. else:
  126. await self.send(text_data = json.dumps(text_data))
  127. async def jm_tmp_dev_sto(self,text_data):
  128. # p("jm_tmp_dev_sto:",text_data)
  129. await self.channel_layer.group_send(self.group_name,{**text_data,"type":"jm_tmp_dev_sto_rec","from":self.channel_name})
  130. sto_event_type = text_data.get("sto_event_type")
  131. if sto_event_type == "db_sync_request":
  132. pass
  133. # TODO:JFI not sure if I will allow m
  134. # await self.get_group_size(text_data)
  135. def time_difs(t0,tfin,tarr):
  136. r = {"arr":[],"td0":tfin-t0,"t0":t0,"tfin":tfin}
  137. cnt=0
  138. tot=0.0
  139. for t in tarr:
  140. r["arr"].append(tfin-t)
  141. tot +=tfin-t
  142. cnt+=1
  143. if cnt:
  144. r["avg_diff"]=tot/cnt
  145. else:
  146. r["avg_diff"]="0/0"
  147. # avg_diff
  148. return r
  149. # r["t0"]=
  150. # t0,tfin,td0
  151. class DevMixin_R3():
  152. # somewhat duplicated in v0.js
  153. async def list_all_room_names(self,text_data):
  154. p(self.scope["url_route"]["kwargs"],self.channel_name)
  155. # p(self.room_name)
  156. p(end="",flush=True)
  157. return
  158. p("self.scope?")
  159. p(self.scope)
  160. for k,v in self.scope.items():
  161. t = type(v)
  162. p((k+ "\t" +str(t)).expandtabs(16))
  163. p(v)
  164. p()
  165. p(end="",flush=True)
  166. async def jm_list_all_room_names(self,text_data):
  167. # await self.channel_layer.group_send("chat_group_t1.all",{"type":"list_all_room_names"})
  168. # await self.list_all_room_names({"type":"list_all_room_names"})
  169. await self.channel_layer.group_send("chat_group_t1.all",{"type":"list_all_room_names"})
  170. p("\n\n\n")
  171. # glob_cl.cbs_once.append(glob_cl.acl.flush())
  172. # class_edit(Mixins.LoneMixinB,RldLoneB1,0,1)
  173. # class_edit(Mixins.LoneMixinA,RldLoneA1,"rmv",1)
  174. class_edit(Mixins.DevMixin,DevMixin_R1)
  175. class_edit(Mixins.DevMixin,DevMixin_R2_DevSto)
  176. class_edit(Mixins.DevMixin,DevMixin_R3)
  177. # p("?")
  178. # print("i1:",dir())
  179. # abc()
  180. # p()
  181. glob_cl.fast_timeout = .1
  182. glob_cl.timeout = 1
  183. # glob_cl.rconn1.set("key_z","am_i persistant?")
  184. # glob_cl.rconn.set("key_y","I_shouldn't_be_here")
  185. # redis_info(glob_cl.rconn1)
  186. # redis_info(glob_cl.rconn)
  187. # glob_cl.fast_timeout = 5.1
  188. # glob_cl.timeout = 5.1