Displaying circle on join
authorDavid Négrier <d.negrier@thecodingmachine.com>
Wed, 13 May 2020 21:11:10 +0000 (23:11 +0200)
committerDavid Négrier <d.negrier@thecodingmachine.com>
Wed, 13 May 2020 21:11:10 +0000 (23:11 +0200)
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
back/src/Model/World.ts

index 60bbe6ad7e0426acdeedac55f09f190fc5634dd2..e3bd54af452909d467c06d2e933bf70757f678b4 100644 (file)
@@ -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);
         }
+
+
     }
 
     /**
index 180740b2d2d6f38b770825f29372fc18b4149d0f..72bf029cf1919f943bd21a27809613d64bc1fcc6 100644 (file)
@@ -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,