Getting rid of roomId in Message class (this is not needed since all messages sent...
authorDavid Négrier <d.negrier@thecodingmachine.com>
Fri, 15 May 2020 22:19:27 +0000 (00:19 +0200)
committerDavid Négrier <d.negrier@thecodingmachine.com>
Fri, 15 May 2020 22:19:27 +0000 (00:19 +0200)
back/src/Controller/IoSocketController.ts
back/src/Model/Websocket/ExtRooms.ts
back/src/Model/Websocket/Message.ts
back/tests/MessageTest.ts
front/src/Connexion.ts

index 2c83a8b5f226a4d61e5ee6216e303fb4630e168a..93dd801075a2352bcb1e18b53f87758377c34763 100644 (file)
@@ -361,12 +361,12 @@ export class IoSocketController {
             character: Client.character,
         };
         let messageUserPosition = new MessageUserPosition(data);
-        let world = this.Worlds.get(messageUserPosition.roomId);
+        let world = this.Worlds.get(Client.roomId);
         if (!world) {
             return;
         }
         world.updatePosition(Client, messageUserPosition.position);
-        this.Worlds.set(messageUserPosition.roomId, world);
+        this.Worlds.set(Client.roomId, world);
     }
 
     //Hydrate and manage error
index 43395a28990ed90e50f0ccc29d9b477fb1f5a6ff..b5493fdb6ba3e82239ef36babf47d13512bc8e3a 100644 (file)
@@ -23,19 +23,18 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
         }
         let data = {
             userId: socket.id,
-            roomId: socket.roomId,
             position: socket.position,
             name: socket.name,
             character: socket.character,
         };
         let dataArray = <any>[];
-        if (mapPositionUserByRoom.get(data.roomId)) {
-            dataArray = mapPositionUserByRoom.get(data.roomId);
+        if (mapPositionUserByRoom.get(socket.roomId)) {
+            dataArray = mapPositionUserByRoom.get(socket.roomId);
             dataArray.push(data);
         } else {
             dataArray = [data];
         }
-        mapPositionUserByRoom.set(data.roomId, dataArray);
+        mapPositionUserByRoom.set(socket.roomId, dataArray);
     }
     rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom);
 };
index 70775d2b24e5583d5428f45b4fe2c14d1bf57816..2e928159f7cf12fc692caba8657d149c7bb00215 100644 (file)
@@ -1,16 +1,14 @@
 export class Message {
     userId: string;
-    roomId: string;
     name: string;
     character: string;
 
     constructor(data: any) {
-        if (!data.userId || !data.roomId) {
+        if (!data.userId) {
             console.error("Got invalid message", data);
-            throw Error("userId or roomId cannot be null");
+            throw Error("userId cannot be null");
         }
         this.userId = data.userId;
-        this.roomId = data.roomId;
         this.name = data.name;
         this.character = data.character;
     }
index ab7d64765074e5e1469640a2510495bcf6792f95..971734c7f1419a01599a68c0a31568ac85bd2195 100644 (file)
@@ -3,32 +3,17 @@ import {Message} from "../src/Model/Websocket/Message";
 
 describe("Message Model", () => {
     it("should find userId and roomId", () => {
-        let message = {userId: "test1", roomId: "test2", name: "foo", character: "user"};
+        let message = {userId: "test1", name: "foo", character: "user"};
         let messageObject = new Message(message);
         expect(messageObject.userId).toBe("test1");
-        expect(messageObject.roomId).toBe("test2");
         expect(messageObject.name).toBe("foo");
         expect(messageObject.character).toBe("user");
     })
 
     it("should find throw error when no userId", () => {
-        let message = {roomId: "test2"};
+        let message = {};
         expect(() => {
             let messageObject = new Message(message);
-        }).toThrow(new Error("userId or roomId cannot be null"));
-    });
-
-    it("should find throw error when no roomId", () => {
-        let message = {userId: "test1"};
-        expect(() => {
-            let messageObject = new Message(message);
-        }).toThrow(new Error("userId or roomId cannot be null"));
-    });
-
-    it("should find throw error when no roomId", () => {
-        let message = {name: "foo"};
-        expect(() => {
-            let messageObject = new Message(message);
-        }).toThrow(new Error("userId or roomId cannot be null"));
+        }).toThrow(new Error("userId cannot be null"));
     });
 })
index da666b8bc8997e6f3cf8283fd10e47b8e5d718d6..f3e4f4cec0dd7f6a29f4b877434275f2805419a6 100644 (file)
@@ -26,13 +26,11 @@ enum EventMessage{
 
 class Message {
     userId: string;
-    roomId: string;
     name: string;
     character: string;
 
-    constructor(userId : string, roomId : string, name: string, character: string) {
+    constructor(userId : string, name: string, character: string) {
         this.userId = userId;
-        this.roomId = roomId;
         this.name = name;
         this.character = character;
     }
@@ -61,7 +59,6 @@ class Point implements PointInterface{
 
 export interface MessageUserPositionInterface {
     userId: string;
-    roomId: string;
     name: string;
     character: string;
     position: PointInterface;
@@ -70,8 +67,8 @@ export interface MessageUserPositionInterface {
 class MessageUserPosition extends Message implements MessageUserPositionInterface{
     position: PointInterface;
 
-    constructor(userId : string, roomId : string, point : Point, name: string, character: string) {
-        super(userId, roomId, name, character);
+    constructor(userId : string, point : Point, name: string, character: string) {
+        super(userId, name, character);
         this.position = point;
     }
 }
@@ -91,7 +88,6 @@ class ListMessageUserPosition {
         data.forEach((userPosition: any) => {
             this.listUsersPosition.push(new MessageUserPosition(
                 userPosition.userId,
-                userPosition.roomId,
                 new Point(
                     userPosition.position.x,
                     userPosition.position.y,