refactor: 抽离出广播方法

This commit is contained in:
CrescentLeaf
2025-10-25 00:48:24 +08:00
parent 2d78e39ca1
commit 760e5a118a
2 changed files with 31 additions and 17 deletions

View File

@@ -34,4 +34,15 @@ export default abstract class BaseApi {
emitToClient(client: SocketIo.Socket, name: ClientEvent, args: { [key: string]: unknown }) {
client.emit("The_White_Silk", name, args)
}
boardcastToUsers(users: string[], name: ClientEvent, args: { [key: string]: unknown }) {
for (const user of users) {
if (ApiManager.checkUserIsOnline(user)) {
const sockets = ApiManager.getUserClientSockets(user)
for (const socket of Object.keys(sockets))
this.emitToClient(sockets[socket], name, args)
} else {
// TODO: EventStore
}
}
}
}