mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-10-31 01:24:43 +00:00 
			
		
		
		
	Automatically close websockets when user sign out
This commit is contained in:
		| @@ -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)); | ||||
		Reference in New Issue
	
	Block a user