Fix mediam stream manage and server back down
This commit is contained in:
parent
ab798b1c09
commit
ab32021fc0
5 changed files with 61 additions and 20 deletions
|
@ -15,21 +15,21 @@ export class AuthenticateController {
|
|||
//permit to login on application. Return token to connect on Websocket IO.
|
||||
login(){
|
||||
// For now, let's completely forget the /login route.
|
||||
/*this.App.post("/login", (req: Request, res: Response) => {
|
||||
this.App.post("/login", (req: Request, res: Response) => {
|
||||
let param = req.body;
|
||||
if(!param.email){
|
||||
/*if(!param.name){
|
||||
return res.status(BAD_REQUEST).send({
|
||||
message: "email parameter is empty"
|
||||
});
|
||||
}
|
||||
}*/
|
||||
//TODO check user email for The Coding Machine game
|
||||
let userId = uuid();
|
||||
let token = Jwt.sign({email: param.email, userId: userId}, SECRET_KEY, {expiresIn: '24h'});
|
||||
let token = Jwt.sign({name: param.name, userId: userId}, SECRET_KEY, {expiresIn: '24h'});
|
||||
return res.status(OK).send({
|
||||
token: token,
|
||||
mapUrlStart: URL_ROOM_STARTED,
|
||||
userId: userId,
|
||||
});
|
||||
});*/
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,25 +39,42 @@ export class IoSocketController {
|
|||
|
||||
// Authentication with token. it will be decoded and stored in the socket.
|
||||
// Completely commented for now, as we do not use the "/login" route at all.
|
||||
/*this.Io.use((socket: Socket, next) => {
|
||||
this.Io.use((socket: Socket, next) => {
|
||||
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) => {
|
||||
Jwt.verify(socket.handshake.query.token, SECRET_KEY, (err: JsonWebTokenError, tokenDecoded: any) => {
|
||||
if (err) {
|
||||
return next(new Error('Authentication error'));
|
||||
}
|
||||
(socket as ExSocketInterface).token = tokenDecoded;
|
||||
(socket as ExSocketInterface).id = tokenDecoded.userId;
|
||||
next();
|
||||
});
|
||||
});*/
|
||||
});
|
||||
|
||||
this.ioConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param token
|
||||
*/
|
||||
searchClientByToken(token: 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.token !== token) {
|
||||
continue
|
||||
}
|
||||
return client;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private sendUpdateGroupEvent(group: Group): void {
|
||||
// Let's get the room of the group. To do this, let's get anyone in the group and find its room.
|
||||
// Note: this is suboptimal
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue