diff --git a/src/controllers/UserWebSocketController.ts b/src/controllers/UserWebSocketController.ts index 0ef3685..c446176 100644 --- a/src/controllers/UserWebSocketController.ts +++ b/src/controllers/UserWebSocketController.ts @@ -8,6 +8,7 @@ import { Request } from 'express'; import { RequestHandler } from '../entities/RequestHandler'; import { time } from '../utils/DateUtils'; import { randomStr } from '../utils/CryptUtils'; +import { EventsHelper } from '../helpers/EventsHelper'; interface PendingRequests { time: number, @@ -121,5 +122,17 @@ export class UserWebSocketController { console.log(this.active_clients) } + /** + * Close a specific user websocket + * + * @param clientID Target client ID + * @param userID Target user ID + */ + public static async CloseClientSockets(clientID: number, userID: number) { + for(const entry of this.active_clients.filter((f) => f.clientID == clientID && f.userID == userID)) + entry.ws.close(); + } } +// When user sign out +EventsHelper.Listen("destroyed_login_tokens", (e) => UserWebSocketController.CloseClientSockets(e.client.id, e.userID)); \ No newline at end of file