1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-21 21:09:22 +00:00

Automatically close websockets when user sign out

This commit is contained in:
Pierre HUBERT 2020-03-30 14:31:04 +02:00
parent 4901e9d3ef
commit 729ee6a2a9

View File

@ -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));