bricks/dist/examples/echo.ws
yumoqing 2e22085122 feat: 401后登录成功自动重试原始请求
- withLoginInfo 改为接收完整 opts(含 method/headers/params)
- 等待 login_window 的 destroy 事件(=登录成功信号)
- 登录成功后重试原始请求
- 重试仍401则返回null(避免死循环)
- 用户手动关闭登录窗口时也触发重试,401则返回null
2026-05-27 15:39:34 +08:00

28 lines
784 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ws_data 客户端传过来的数据
# ws_pool 保存所有链接
# register(id)
# 注册自己id必须唯一
# sendto(data, id=None)
# 发送消息给客户端当id为空时发送给当前链接的客户端否则发送给id指定的客户端
# is_online(id)
# 检查id指定的客户端是否在线
# user = await get_user()
userid = 'kkkkk'
ws_pool.register(userid)
resp = 'resp=' + ws_data
if ws_pool.is_online(userid):
print(f'{userid=} is online')
ret = {
'efew':1,
'g':3
}
r = await ws_pool.sendto(ret, userid)
print(f'{ret=} send return {r}')
else:
print(f'{userid=} is not online')
print(f'{resp=}, {ws_pool.get_data()=}')
await ws_pool.sendto(resp)
# if ws_pool.is_online('bington'):
# await ws_pool.sendto(resp, 'bington')