Multi players on the map

- Fix share user position
 - Fix initialise map
 - Create function to add user on the map with back end data
This commit is contained in:
gparant 2020-04-10 12:54:05 +02:00
parent 6bec8b3703
commit d257b2b944
10 changed files with 253 additions and 48 deletions

View file

@ -2,6 +2,7 @@ import {Application, Request, Response} from "express";
import Jwt from "jsonwebtoken";
import {BAD_REQUEST, OK} from "http-status-codes";
import {SECRET_KEY, ROOM} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
import { uuid } from 'uuidv4';
export class AuthenticateController{
App : Application;
@ -21,8 +22,13 @@ export class AuthenticateController{
});
}
//TODO check user email for The Coding Machine game
let token = Jwt.sign({email: param.email, roomId: ROOM}, SECRET_KEY, {expiresIn: '24h'});
return res.status(OK).send({token: token, roomId: ROOM});
let userId = uuid();
let token = Jwt.sign({email: param.email, roomId: ROOM, userId: userId}, SECRET_KEY, {expiresIn: '24h'});
return res.status(OK).send({
token: token,
roomId: ROOM,
userId: userId
});
});
}
}

View file

@ -125,8 +125,7 @@ export class IoSocketController{
}
arrayMap.forEach((value : any) => {
let roomId = value[0];
let data = value[1];
this.Io.in(roomId).emit('user-position', JSON.stringify(data));
this.Io.in(roomId).emit('user-position', JSON.stringify(arrayMap));
});
this.seTimeOutInProgress = setTimeout(() => {
this.shareUsersPosition();