Permit to dissociate data by room
- Update share room id. - Join room when a scene is loaded. - Add a room in constant variable.
This commit is contained in:
parent
27c6034661
commit
5f11b065e1
7 changed files with 46 additions and 27 deletions
|
@ -1,7 +1,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 {SECRET_KEY, ROOM_STARTED, URL_ROOM_STARTED} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
|
||||
import { uuid } from 'uuidv4';
|
||||
|
||||
export class AuthenticateController{
|
||||
|
@ -23,15 +23,11 @@ export class AuthenticateController{
|
|||
}
|
||||
//TODO check user email for The Coding Machine game
|
||||
let userId = uuid();
|
||||
let token = Jwt.sign({email: param.email, roomId: ROOM, userId: userId}, SECRET_KEY, {expiresIn: '24h'});
|
||||
let token = Jwt.sign({email: param.email, userId: userId}, SECRET_KEY, {expiresIn: '24h'});
|
||||
return res.status(OK).send({
|
||||
token: token,
|
||||
roomId: ROOM,
|
||||
startedRoom: {key: ROOM_STARTED, url: URL_ROOM_STARTED},
|
||||
userId: userId,
|
||||
maps: [
|
||||
"floor0",
|
||||
"floor1"
|
||||
]
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -104,6 +104,15 @@ export class IoSocketController {
|
|||
return socket.emit(SockerIoEvent.MESSAGE_ERROR, JSON.stringify({message: messageUserPosition.message}))
|
||||
}
|
||||
|
||||
if((socket as ExSocketInterface).roomId === messageUserPosition.roomId){
|
||||
return;
|
||||
}
|
||||
|
||||
//lease previous room
|
||||
if((socket as ExSocketInterface).roomId){
|
||||
socket.leave((socket as ExSocketInterface).roomId);
|
||||
}
|
||||
|
||||
//join user in room
|
||||
socket.join(messageUserPosition.roomId);
|
||||
|
||||
|
@ -308,7 +317,7 @@ export class IoSocketController {
|
|||
}
|
||||
arrayMap.forEach((value: any) => {
|
||||
let roomId = value[0];
|
||||
this.Io.in(roomId).emit(SockerIoEvent.USER_POSITION, JSON.stringify(arrayMap));
|
||||
this.Io.in(roomId).emit(SockerIoEvent.USER_POSITION, JSON.stringify(value));
|
||||
});
|
||||
this.seTimeOutInProgress = setTimeout(() => {
|
||||
this.shareUsersPosition();
|
||||
|
|
|
@ -2,6 +2,7 @@ import express from "express";
|
|||
import path from "path";
|
||||
import {Application, Request, Response} from "express";
|
||||
import {OK} from "http-status-codes";
|
||||
import {ROOM_STARTED, ROOMS, URL_ROOM_STARTED} from "../Enum/EnvironmentVariable";
|
||||
|
||||
export class MapController {
|
||||
App: Application;
|
||||
|
@ -20,11 +21,8 @@ export class MapController {
|
|||
getMpas() {
|
||||
this.App.get("/maps", (req: Request, res: Response) => {
|
||||
return res.status(OK).send({
|
||||
mapStart: {key: "floor0", url: "/map/files/Floor0"},
|
||||
maps: [
|
||||
{key: "floor0", url: "/map/files/Floor0"},
|
||||
{key: "floor1", url: "/map/files/Floor1"},
|
||||
]
|
||||
mapStart: {key: ROOM_STARTED, url: URL_ROOM_STARTED},
|
||||
maps: ROOMS
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
const SECRET_KEY = process.env.SECRET_KEY || "THECODINGMACHINE_SECRET_KEY";
|
||||
const ROOM = process.env.ROOM || "THECODINGMACHINE";
|
||||
const ROOM_STARTED = "floor0";
|
||||
const URL_ROOM_STARTED = "/map/files/Floor0";
|
||||
const ROOMS = [
|
||||
{key: "floor0", url: "/map/files/Floor0"},
|
||||
{key: "floor1", url: "/map/files/Floor1"},
|
||||
]
|
||||
const MINIMUM_DISTANCE = process.env.MINIMUM_DISTANCE ? Number(process.env.MINIMUM_DISTANCE) : 64;
|
||||
const GROUP_RADIUS = process.env.GROUP_RADIUS ? Number(process.env.GROUP_RADIUS) : 48;
|
||||
|
||||
export {
|
||||
SECRET_KEY,
|
||||
ROOM,
|
||||
ROOM_STARTED,
|
||||
URL_ROOM_STARTED,
|
||||
ROOMS,
|
||||
MINIMUM_DISTANCE,
|
||||
GROUP_RADIUS
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue