mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-24 22:39:21 +00:00
Maintain a list of active connections
This commit is contained in:
parent
fa5335f156
commit
4bfcb9b35b
@ -11,10 +11,17 @@ import { randomStr } from '../utils/CryptUtils';
|
|||||||
|
|
||||||
interface PendingRequests {
|
interface PendingRequests {
|
||||||
time: number,
|
time: number,
|
||||||
|
clientID: number,
|
||||||
userID: number,
|
userID: number,
|
||||||
token: string
|
token: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ActiveClient {
|
||||||
|
clientID: number,
|
||||||
|
userID: number,
|
||||||
|
ws: ws
|
||||||
|
}
|
||||||
|
|
||||||
// Tokens are valid only 10 seconds after they are generated
|
// Tokens are valid only 10 seconds after they are generated
|
||||||
const TOKENS_DURATION = 10
|
const TOKENS_DURATION = 10
|
||||||
const TOKEN_LENGTH = 20
|
const TOKEN_LENGTH = 20
|
||||||
@ -26,6 +33,11 @@ export class UserWebSocketController {
|
|||||||
*/
|
*/
|
||||||
static pending_list: PendingRequests[] = []
|
static pending_list: PendingRequests[] = []
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of active clients
|
||||||
|
*/
|
||||||
|
static active_clients: ActiveClient[] = []
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean the list of tokens
|
* Clean the list of tokens
|
||||||
*/
|
*/
|
||||||
@ -49,6 +61,7 @@ export class UserWebSocketController {
|
|||||||
// Add the token to the list
|
// Add the token to the list
|
||||||
this.pending_list.push({
|
this.pending_list.push({
|
||||||
time: time(),
|
time: time(),
|
||||||
|
clientID: h.getClientInfo().id,
|
||||||
userID: h.getUserId(),
|
userID: h.getUserId(),
|
||||||
token: token
|
token: token
|
||||||
});
|
});
|
||||||
@ -89,7 +102,23 @@ export class UserWebSocketController {
|
|||||||
const entry = this.pending_list[entryIndex];
|
const entry = this.pending_list[entryIndex];
|
||||||
this.pending_list.splice(entryIndex, 1);
|
this.pending_list.splice(entryIndex, 1);
|
||||||
|
|
||||||
console.log(entry)
|
// Add the client to the list of active clients
|
||||||
|
const client: ActiveClient = {
|
||||||
|
clientID: entry.clientID,
|
||||||
|
userID: entry.userID,
|
||||||
|
ws: ws
|
||||||
|
}
|
||||||
|
this.active_clients.push(client);
|
||||||
|
|
||||||
|
|
||||||
|
// Remove the client for the list as soon as the
|
||||||
|
// socket is closed
|
||||||
|
ws.addEventListener("close", () => {
|
||||||
|
this.active_clients.splice(this.active_clients.indexOf(client), 1);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
console.log(this.active_clients)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user