kboss/b/pub/cpcc.ws
2025-07-16 14:27:17 +08:00

29 lines
1.0 KiB
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指定的客户端是否在线
debug("chuan shu neirong: %s" % ws_data)
print("chuan shu neirong: %s" % ws_data)
ns = json.loads(ws_data)
print('获取新内容: ', ws_data)
user_id = ns['userid']
ws_pool.register(user_id)
# d = ws_pool.get_data()
# await ws_pool.sendto(ws_data, None)
try:
if ws_pool.is_online(user_id):
await ws_pool.sendto(ws_data, user_id)
else:
ns['status'] = False
await ws_pool.sendto(json.dumps(ns), user_id)
except Exception as e:
await ws_pool.sendto('当前客户已经离线', None)
# {'status': False, 'msg': '客服正在通话中, 请稍后重试', 'data': ws_data, 'pool': dir(ws_pool),
# 'judge_%s' % receiver_id: ws_pool.is_online(receiver_id), 'register_now': user_id}