Auto-reconnect
This commit is contained in:
parent
dd5a0c9933
commit
ec297e3912
7 changed files with 118 additions and 15 deletions
|
@ -37,6 +37,9 @@ export class IoSocketController {
|
|||
if (!socket.handshake.query || !socket.handshake.query.token) {
|
||||
return next(new Error('Authentication error'));
|
||||
}
|
||||
if(this.searchClientByToken(socket.handshake.query.token)){
|
||||
return next(new Error('Authentication error'));
|
||||
}
|
||||
Jwt.verify(socket.handshake.query.token, SECRET_KEY, (err: JsonWebTokenError, tokenDecoded: object) => {
|
||||
if (err) {
|
||||
return next(new Error('Authentication error'));
|
||||
|
@ -206,6 +209,21 @@ export class IoSocketController {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId
|
||||
*/
|
||||
searchClientByToken(userId: string): ExSocketInterface | null {
|
||||
let clients: Array<any> = Object.values(this.Io.sockets.sockets);
|
||||
for (let i = 0; i < clients.length; i++) {
|
||||
let client: ExSocketInterface = clients[i];
|
||||
if (client.userId !== userId) {
|
||||
continue
|
||||
}
|
||||
return client;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Client: ExSocketInterface
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue