partey_workadventure/front/src/Administration/UserMessageManager.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

import {RoomConnection} from "../Connexion/RoomConnection";
import * as TypeMessages from "./TypeMessage";
2020-10-19 21:04:16 +02:00
export interface TypeMessageInterface {
showMessage(message: string): void;
}
export class UserMessageManager {
2020-10-19 21:04:16 +02:00
typeMessages: Map<string, TypeMessageInterface> = new Map<string, TypeMessageInterface>();
constructor(private Connection: RoomConnection) {
2020-10-19 21:04:16 +02:00
const valueTypeMessageTab = Object.values(TypeMessages);
Object.keys(TypeMessages).forEach((value: string, index: number) => {
2020-10-19 21:04:16 +02:00
const typeMessageInstance: TypeMessageInterface = (new valueTypeMessageTab[index]() as TypeMessageInterface);
this.typeMessages.set(value.toLowerCase(), typeMessageInstance);
});
this.initialise();
}
2020-10-19 21:04:16 +02:00
initialise() {
//receive signal to show message
this.Connection.receiveUserMessage((type: string, message: string) => {
this.showMessage(type, message);
});
}
2020-10-19 21:04:16 +02:00
showMessage(type: string, message: string) {
const classTypeMessage = this.typeMessages.get(type.toLowerCase());
if (!classTypeMessage) {
console.error('Message unknown');
return;
}
classTypeMessage.showMessage(message);
}
2020-10-19 21:04:16 +02:00
}