class DevMixin_R1(): async def az_call(self, *a,**kw): await asyncio.sleep(0.001) p("az_call:") p(end="",flush=True) async def ws_conn(self, *a,**kw): if not getattr(glob_cl,"z",None): glob_cl.z=self # p("????????????") await glob_cl.dev_group_add("chat_group_t1.all",self) # TODO:JFI group name needs a namespace to prevent collisions self.group_name= self.scope["url_route"]["kwargs"]["room_name"] # await glob_cl.dev_group_add("chat_group_t1.:all",self) await glob_cl.dev_group_add(self.group_name,self) async def con_ping0(self, text_data): p("con_ping0:") p(end="",flush=True) async def con_ping(self, text_data): # p("con_ping:",text_data) p("con_ping:") p(end="",flush=True) # p("!!!.?",flush=True) # p(flush=True) p(end="",flush=True) async def jm_group_size(self, text_data): await self.channel_layer.group_send(self.group_name,{"type":"con_ping","return_addr":self.channel_name}) p("????????\n") asyncio.ensure_future(self.az_call()) # glob_cl.loop.create_task(self.az_call()) # glob_cl.loop.ensure_future(self.az_call()) p(end="",flush=True) # return # await asyncio.sleep(0.001) p("!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") p(end="",flush=True) async def jsto_send(self, text_data): p("jsto_send:",type(text_data)) p(text_data) await self.send(text_data = json.dumps(text_data)) async def jsend(self, text_data): p("jsend:",type(text_data)) p(text_data) await self.send(text_data = json.dumps(text_data["payload"])) async def jm_group_sto_message(self, text_data): await self.channel_layer.group_send(self.group_name,{"payload":text_data,"type":"jsto_send"}) async def jm_group_message(self, text_data): await self.channel_layer.group_send(self.group_name,{"payload":text_data,"type":"jsend"}) async def jm_mtypex(self, text_data): p(self.groups) # p("abc") await self.send(text_data=json.dumps({ "type":"z", 'm1': {"abc.":123} })) # await self.channel_layer.group_send("group1",self.channel_name) await self.channel_layer.group_send(self.group_name,{"zz":"HI...","type":"zz"}) await self.channel_layer.send(self.channel_name,{"zz":"HI","type":"zz"}) async def zz(self, text_data): p("HELO>???",text_data) class DevMixin_R2_DevSto(): async def ws_conn(self, *a,**kw): self.group_count = 0 # r''' await self.get_group_size({ "CLIENT_KEY": "ws_sto", "group_count": -1, "sto_event_type": "group_count", "ws_conn":"???", }) # ''' # r''' await self.send(text_data = json.dumps({ "CLIENT_KEY":"ws_sto", "sto_event_type": "connection_info", "channel_name":self.channel_name, "group_name":self.group_name, })) # ''' async def ws_disconn(self, close_code): # TODO:JFI maybe call jm_tmp_dev_sto? await self.channel_layer.group_send(self.group_name,{"type":"jm_tmp_dev_sto_rec","from":self.channel_name, "CLIENT_KEY":"ws_sto", "sto_event_type": "user_disconnected", "group_name":self.group_name, "channel_name":self.channel_name, }) # r''' # ''' r''' await self.send(text_data=json.dumps({ "sto_event_type": "user_disconnected", "channel_name":self.channel_name, "group_name":self.group_name, })) # ''' async def group_size_count(self,*a,**kw): # await asyncio.sleep(0.1) # p("method/fn:",inspect.stack()[0][3]) self.gc_t_fin =time.time() # 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})) # 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)})) await self.send(text_data=json.dumps({"CLIENT_KEY":"ws_sto","group_count":self.group_count,"sto_event_type":"group_count"})) pass async def group_size_pong(self,text_data): self.group_count += 1 self.gc_t_arr.append(time.time()) async def group_size_ping(self,text_data): await self.channel_layer.send(text_data["from"],{"type":"group_size_pong","from":self.channel_name}) # p("group_size_ping") async def jm_get_group_size(self,text_data): await self.get_group_size(text_data) async def get_group_size(self,text_data): self.group_count = 0 self.gc_t_0=time.time() self.gc_t_arr=[] # p(self.gc_ts1) await self.channel_layer.group_send(self.group_name,{"type":"group_size_ping","from":self.channel_name}) glob_cl.cbs_asap.append(self.group_size_count) async def jm_tmp_dev_sto_rec(self,text_data): _from = text_data.get("from") pass if (_from == self.channel_name): await self.send(text_data = json.dumps(text_data)) pass else: await self.send(text_data = json.dumps(text_data)) async def jm_tmp_dev_sto(self,text_data): # p("jm_tmp_dev_sto:",text_data) await self.channel_layer.group_send(self.group_name,{**text_data,"type":"jm_tmp_dev_sto_rec","from":self.channel_name}) sto_event_type = text_data.get("sto_event_type") if sto_event_type == "db_sync_request": pass # TODO:JFI not sure if I will allow m # await self.get_group_size(text_data) def time_difs(t0,tfin,tarr): r = {"arr":[],"td0":tfin-t0,"t0":t0,"tfin":tfin} cnt=0 tot=0.0 for t in tarr: r["arr"].append(tfin-t) tot +=tfin-t cnt+=1 if cnt: r["avg_diff"]=tot/cnt else: r["avg_diff"]="0/0" # avg_diff return r # r["t0"]= # t0,tfin,td0 class DevMixin_R3(): # somewhat duplicated in v0.js async def list_all_room_names(self,text_data): p(self.scope["url_route"]["kwargs"],self.channel_name) # p(self.room_name) p(end="",flush=True) return p("self.scope?") p(self.scope) for k,v in self.scope.items(): t = type(v) p((k+ "\t" +str(t)).expandtabs(16)) p(v) p() p(end="",flush=True) async def jm_list_all_room_names(self,text_data): # await self.channel_layer.group_send("chat_group_t1.all",{"type":"list_all_room_names"}) # await self.list_all_room_names({"type":"list_all_room_names"}) await self.channel_layer.group_send("chat_group_t1.all",{"type":"list_all_room_names"}) p("\n\n\n") # glob_cl.cbs_once.append(glob_cl.acl.flush()) # class_edit(Mixins.LoneMixinB,RldLoneB1,0,1) # class_edit(Mixins.LoneMixinA,RldLoneA1,"rmv",1) class_edit(Mixins.DevMixin,DevMixin_R1) class_edit(Mixins.DevMixin,DevMixin_R2_DevSto) class_edit(Mixins.DevMixin,DevMixin_R3) # p("?") # print("i1:",dir()) # abc() # p() glob_cl.fast_timeout = .1 glob_cl.timeout = 1 # glob_cl.rconn1.set("key_z","am_i persistant?") # glob_cl.rconn.set("key_y","I_shouldn't_be_here") # redis_info(glob_cl.rconn1) # redis_info(glob_cl.rconn) # glob_cl.fast_timeout = 5.1 # glob_cl.timeout = 5.1