1
0
forked from noxious/server

Added socket helper functions

This commit is contained in:
2024-12-31 15:27:31 +01:00
parent ba12674e7c
commit 9d6a8730a9
2 changed files with 55 additions and 45 deletions

View File

@ -107,6 +107,16 @@ class SocketManager {
public emitToRoom(room: string, event: string, ...args: any[]): void {
this.getIO().to(room).emit(event, ...args)
}
public getSocketByUserId(userId: number): TSocket | undefined {
const sockets = Array.from(this.getIO().sockets.sockets.values());
return sockets.find((socket: TSocket) => socket.userId === userId);
}
public getSocketByCharacterId(characterId: number): TSocket | undefined {
const sockets = Array.from(this.getIO().sockets.sockets.values());
return sockets.find((socket: TSocket) => socket.characterId === characterId);
}
}
export default new SocketManager()