workadventure/back/src/Model/Websocket/MessageUserPosition.ts
gparant 7e08e7f133 Front : create class to connect, send and receive message
- Create environment class
 - Create Connexion class to connect and save data
 - Refactor back api
2020-04-05 20:57:14 +02:00

42 lines
926 B
TypeScript

import {Message} from "./Message";
import {PointInterface} from "./PointInterface";
export class Point implements PointInterface{
x: number;
y: number;
constructor(x : number, y : number) {
if(x === null || y === null){
throw Error("position x and y cannot be null");
}
this.x = x;
this.y = y;
}
toJson(){
return {
x : this.x,
y: this.y
}
}
}
export class MessageUserPosition extends Message{
position: PointInterface;
constructor(message: string) {
super(message);
let data = JSON.parse(message);
this.position = new Point(data.position.x, data.position.y);
}
toString() {
return JSON.stringify(
Object.assign(
super.toJson(),
{
position: this.position.toJson()
})
);
}
}