From 8df56204e34c53e2c9b0025c9be8e4ec84e2482b Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Thu, 15 Oct 2020 11:51:24 +0200 Subject: [PATCH] Add teleport event --- back/src/Controller/IoSocketController.ts | 12 ++++++++---- back/src/Controller/ReportController.ts | 5 ++++- front/src/Administration/GlobalMessageManager.ts | 6 ++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index d39c9eb3..4dfe3576 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -891,12 +891,16 @@ export class IoSocketController { } public teleport(userUuid: string) { - const user = this.searchClientByUuid(userUuid); - if(!user){ + const userSocket = this.searchClientByUuid(userUuid); + if (!userSocket) { throw 'User not found'; } const teleportMessageMessage = new TeleportMessageMessage(); - teleportMessageMessage.setMap(`/teleport/${user.userUuid}`); - user.send(teleportMessageMessage.serializeBinary().buffer, true); + teleportMessageMessage.setMap(`wait/${userSocket.userUuid}`); + + const serverToClientMessage = new ServerToClientMessage(); + serverToClientMessage.setTeleportmessagemessage(teleportMessageMessage); + + userSocket.send(serverToClientMessage.serializeBinary().buffer, true); } } diff --git a/back/src/Controller/ReportController.ts b/back/src/Controller/ReportController.ts index d39e9816..5b5e342d 100644 --- a/back/src/Controller/ReportController.ts +++ b/back/src/Controller/ReportController.ts @@ -27,7 +27,10 @@ export class ReportController extends BaseController { }) const param = await res.json(); this.ioSocketController.teleport(param.userUuid); - res.writeStatus("200 OK").end(); + res.writeHeader('Content-Type', 'application/json'); + res.writeStatus("200 OK").end(JSON.stringify({ + mapUrl: `wait/${param.userUuid}` + })); } catch (e) { console.log("An error happened", e) res.writeStatus(e.status || "500 Internal Server Error").end('An error happened'); diff --git a/front/src/Administration/GlobalMessageManager.ts b/front/src/Administration/GlobalMessageManager.ts index 963db8cc..e3b2b503 100644 --- a/front/src/Administration/GlobalMessageManager.ts +++ b/front/src/Administration/GlobalMessageManager.ts @@ -20,6 +20,12 @@ export class GlobalMessageManager { this.Connection.receiveStopGlobalMessage((messageId: string) => { this.stopMessage(messageId); }); + + //receive signal to close message + this.Connection.receiveTeleportMessage((map: string) => { + console.log('map to teleport user', map); + //TODO teleport user on map + }); } private playMessage(message : PlayGlobalMessageInterface){