forked from noxious/server
Added socket helper functions
This commit is contained in:
@ -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()
|
Reference in New Issue
Block a user