33 lines
431 B
TypeScript
33 lines
431 B
TypeScript
|
|
||
|
export const TypeMessage = "message"
|
||
|
|
||
|
export class Message {
|
||
|
_type: string
|
||
|
_payload: any
|
||
|
|
||
|
constructor(type, payload) {
|
||
|
this._type = type;
|
||
|
this._payload = payload;
|
||
|
}
|
||
|
|
||
|
getType() {
|
||
|
return this._type;
|
||
|
}
|
||
|
|
||
|
getPayload() {
|
||
|
return this._payload;
|
||
|
}
|
||
|
|
||
|
toJSON() {
|
||
|
return {
|
||
|
t: this._type,
|
||
|
p: this._payload
|
||
|
};
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export function messageFrom(raw) {
|
||
|
return new Message(raw.t, raw.p);
|
||
|
}
|