53 lines
1.3 KiB
Plaintext
53 lines
1.3 KiB
Plaintext
async def online2all():
|
|
nodes = ws_pool.get_data().nodes or {}
|
|
lst = [{x:y for x,y in v.items() if x != 'ws' } for v in nodes.values()]
|
|
d = DictObject(type='online', online=lst)
|
|
info(f'{d=}, {lst=}')
|
|
for i in lst:
|
|
d1 = [ x for x in lst if x['id'] != i['id'] ]
|
|
d = {
|
|
'type':'online',
|
|
'online':d1
|
|
}
|
|
debug(f'send online {d}, {i=}')
|
|
await ws_pool.sendto(d, id=i['id'])
|
|
|
|
info(f'{ws_data=}')
|
|
v = json.loads(ws_data)
|
|
client_data = DictObject(**v)
|
|
try:
|
|
if client_data.type == 'login':
|
|
ws_pool.add_me(client_data.msgfrom.copy());
|
|
info(f'1 ========client_data={client_data},{ws_pool.get_data().nodes=}')
|
|
await online2all()
|
|
info(f'2 ========client_data={client_data}')
|
|
return
|
|
|
|
if client_data.type == 'logout':
|
|
ws_pool.remove_me()
|
|
online2all()
|
|
return
|
|
|
|
if client_data.type == 'new_session':
|
|
ws_pool.add_session(client_data.session)
|
|
d = {
|
|
"session":client_data.session,
|
|
"type":"sessioncreated"
|
|
}
|
|
debug(f'send back {d}')
|
|
await ws_pool.sendto(d, id=client_data.msgfrom.id)
|
|
return
|
|
|
|
#
|
|
# for the following type
|
|
# [ 'callRequest', 'offer', 'iceCandidate', 'callAccepted', 'callRejected',
|
|
# 'disconnect', 'answer']:
|
|
#
|
|
|
|
if client_data.msgto:
|
|
await ws_pool.sendto(client_data, id=client_data.msgto.id)
|
|
return
|
|
except Exception as e:
|
|
ti = format_exc()
|
|
exception(f'exception:{e=}\n{ti}')
|