workadventure/back/src/Model/Websocket/Message.ts
2020-05-13 22:11:05 +02:00

27 lines
636 B
TypeScript

export class Message {
userId: string;
roomId: string;
name: string;
character: string;
constructor(data: any) {
if (!data.userId || !data.roomId) {
console.error("Got invalid message", data);
throw Error("userId or roomId cannot be null");
}
this.userId = data.userId;
this.roomId = data.roomId;
this.name = data.name;
this.character = data.character;
}
toJson() {
return {
userId: this.userId,
roomId: this.roomId,
name: this.name,
character: this.character
}
}
}