Getting rid of roomId in Message class (this is not needed since all messages sent are for the room we are currently in)
This commit is contained in:
parent
4d1c3517ec
commit
3b6ace03fa
5 changed files with 13 additions and 35 deletions
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue