From 4cca1c1e584f15f9fc4b5181b6d70a9bceff6cc1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20N=C3=A9grier?= Date: Wed, 13 May 2020 23:11:10 +0200 Subject: [PATCH] Displaying circle on join So far, someone joining a map would not see the circles of groups already formed until someone moves in the group (because the "circle_moved_or_updated" event was not fired when someone arrives) This commit fixes this behaviour. Someone entering a room will receive an event for each and every group currently formed. --- back/src/Controller/IoSocketController.ts | 13 ++++++++++++- back/src/Model/World.ts | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index 60bbe6a..e3bd54a 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -281,12 +281,23 @@ export class IoSocketController { this.Worlds.set(messageUserPosition.roomId, world); } - //join world let world : World|undefined = this.Worlds.get(messageUserPosition.roomId); + + if(world) { + // Dispatch groups position to newly connected user + world.getGroups().forEach((group: Group) => { + Client.emit(SockerIoEvent.GROUP_CREATE_UPDATE, { + position: group.getPosition(), + groupId: group.getId() + }); + }); + //join world world.join(messageUserPosition); this.Worlds.set(messageUserPosition.roomId, world); } + + } /** diff --git a/back/src/Model/World.ts b/back/src/Model/World.ts index 180740b..72bf029 100644 --- a/back/src/Model/World.ts +++ b/back/src/Model/World.ts @@ -43,6 +43,10 @@ export class World { this.groupDeletedCallback = groupDeletedCallback; } + public getGroups(): Group[] { + return this.groups; + } + public join(userPosition: MessageUserPosition): void { this.users.set(userPosition.userId, { id: userPosition.userId, -- 2.25.1