From e35c188854c1c6e0cb1fe931f1e40c39a1c0edb5 Mon Sep 17 00:00:00 2001 From: gparant Date: Mon, 11 May 2020 13:17:02 +0200 Subject: [PATCH 1/3] Fix update world back end and deleting group in front end --- back/src/Controller/IoSocketController.ts | 30 ++++++++++++++++++----- back/src/Model/Websocket/ExtRooms.ts | 12 --------- front/src/Phaser/Game/GameScene.ts | 3 +++ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index e0840c69..c855c66a 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -109,7 +109,7 @@ export class IoSocketController { this.saveUserInformation(Client, messageUserPosition); //add function to refresh position user in real time. - this.refreshUserPosition(); + this.refreshUserPosition(Client); socket.to(messageUserPosition.roomId).emit(SockerIoEvent.JOIN_ROOM, messageUserPosition.toString()); }); @@ -120,11 +120,13 @@ export class IoSocketController { return socket.emit(SockerIoEvent.MESSAGE_ERROR, JSON.stringify({message: messageUserPosition.message})); } + let Client = (socket as ExSocketInterface); + // sending to all clients in room except sender - this.saveUserInformation((socket as ExSocketInterface), messageUserPosition); + this.saveUserInformation(Client, messageUserPosition); //refresh position of all user in all rooms in real time - this.refreshUserPosition(); + this.refreshUserPosition(Client); }); socket.on(SockerIoEvent.WEBRTC_SIGNAL, (message: string) => { @@ -155,7 +157,7 @@ export class IoSocketController { this.sendDisconnectedEvent(Client); //refresh position of all user in all rooms in real time - this.refreshUserPosition(); + this.refreshUserPosition(Client); //leave room this.leaveRoom(Client); @@ -299,13 +301,29 @@ export class IoSocketController { socket.character = message.character; } - refreshUserPosition() { + refreshUserPosition(Client : ExSocketInterface) { //refresh position of all user in all rooms in real time let rooms = (this.Io.sockets.adapter.rooms as ExtRoomsInterface); if (!rooms.refreshUserPosition) { rooms.refreshUserPosition = RefreshUserPositionFunction; } - rooms.refreshUserPosition(rooms, this.Io, this.Worlds); + rooms.refreshUserPosition(rooms, this.Io); + + // update position in the worl + let data = { + userId: Client.userId, + roomId: Client.roomId, + position: Client.position, + name: Client.name, + character: Client.character, + }; + let messageUserPosition = new MessageUserPosition(data); + let world = this.Worlds.get(messageUserPosition.roomId); + if (!world) { + return; + } + world.updatePosition(messageUserPosition); + this.Worlds.set(messageUserPosition.roomId, world); } //Hydrate and manage error diff --git a/back/src/Model/Websocket/ExtRooms.ts b/back/src/Model/Websocket/ExtRooms.ts index 22db4fdc..bb49283d 100644 --- a/back/src/Model/Websocket/ExtRooms.ts +++ b/back/src/Model/Websocket/ExtRooms.ts @@ -38,18 +38,6 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server dataArray = [data]; } mapPositionUserByRoom.set(data.roomId, dataArray); - - // update position in the worl - if (!Worlds) { - return; - } - let messageUserPosition = new MessageUserPosition(data); - let world = Worlds.get(messageUserPosition.roomId); - if (!world) { - return; - } - world.updatePosition(messageUserPosition); - Worlds.set(messageUserPosition.roomId, world); } rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom); } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 26b4fe95..86988a8b 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -411,6 +411,9 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat } deleteGroup(groupId: string): void { + if(!this.groups.get(groupId)){ + return; + } this.groups.get(groupId).destroy(); this.groups.delete(groupId); } From 099961b818722495296733ff6ba54c3983c428e3 Mon Sep 17 00:00:00 2001 From: gparant Date: Mon, 11 May 2020 13:19:48 +0200 Subject: [PATCH 2/3] Delete params not used --- back/src/Model/Websocket/ExtRooms.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/back/src/Model/Websocket/ExtRooms.ts b/back/src/Model/Websocket/ExtRooms.ts index bb49283d..f0eadea6 100644 --- a/back/src/Model/Websocket/ExtRooms.ts +++ b/back/src/Model/Websocket/ExtRooms.ts @@ -1,8 +1,6 @@ import {ExtRoomsInterface} from "./ExtRoomsInterface"; import socketIO = require('socket.io'); import {ExSocketInterface} from "./ExSocketInterface"; -import {MessageUserPosition} from "./MessageUserPosition"; -import {World} from "_Model/World"; export class ExtRooms implements ExtRoomsInterface{ userPositionMapByRoom: any; @@ -10,9 +8,9 @@ export class ExtRooms implements ExtRoomsInterface{ Worlds: any; [room: string]: SocketIO.Room; -} +}; -let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server, Worlds: Map) { +let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server) { let clients = Io.clients(); let socketsKey = Object.keys(Io.clients().sockets); @@ -40,8 +38,8 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server mapPositionUserByRoom.set(data.roomId, dataArray); } rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom); -} +}; export { RefreshUserPositionFunction -} +}; From bd2ffde4c4338990bb8e9c32cc63856cde9e43ff Mon Sep 17 00:00:00 2001 From: gparant Date: Mon, 11 May 2020 20:55:17 +0200 Subject: [PATCH 3/3] Fix CI lint --- back/src/Model/Websocket/ExtRooms.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/src/Model/Websocket/ExtRooms.ts b/back/src/Model/Websocket/ExtRooms.ts index f0eadea6..7fb6216d 100644 --- a/back/src/Model/Websocket/ExtRooms.ts +++ b/back/src/Model/Websocket/ExtRooms.ts @@ -8,7 +8,7 @@ export class ExtRooms implements ExtRoomsInterface{ Worlds: any; [room: string]: SocketIO.Room; -}; +} let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server) { let clients = Io.clients();