def broadcast(cls, data):
username, payload = [d.decode('utf-8') for d in data]
if username == '*':
print('[WebSocket] Forwarding message to all users')
all_sockets = [socket
for socket_list in cls.sockets.values()
for socket in socket_list]
for socket in all_sockets:
socket.write_message(payload)
else:
for socket in cls.sockets[username]:
print(f'[WebSocket] Forwarding message to {username}')
socket.write_message(payload)
评论列表
文章目录