2020-10-19 19:32:47 +02:00
|
|
|
import {RoomConnection} from "../Connexion/RoomConnection";
|
|
|
|
import * as TypeMessages from "./TypeMessage";
|
2021-01-25 14:10:16 +01:00
|
|
|
import List = Phaser.Structs.List;
|
|
|
|
import {UpdatedLocalStreamCallback} from "../WebRtc/MediaManager";
|
|
|
|
import {Banned} from "./TypeMessage";
|
2020-10-19 19:32:47 +02:00
|
|
|
|
2020-10-19 21:04:16 +02:00
|
|
|
export interface TypeMessageInterface {
|
|
|
|
showMessage(message: string): void;
|
|
|
|
}
|
2020-10-19 19:32:47 +02:00
|
|
|
|
|
|
|
export class UserMessageManager {
|
|
|
|
|
2020-10-19 21:04:16 +02:00
|
|
|
typeMessages: Map<string, TypeMessageInterface> = new Map<string, TypeMessageInterface>();
|
2021-01-25 14:10:16 +01:00
|
|
|
receiveBannedMessageListener: Set<Function> = new Set<UpdatedLocalStreamCallback>();
|
2020-10-19 19:32:47 +02:00
|
|
|
|
|
|
|
constructor(private Connection: RoomConnection) {
|
2020-10-19 21:04:16 +02:00
|
|
|
const valueTypeMessageTab = Object.values(TypeMessages);
|
2020-10-19 19:32:47 +02:00
|
|
|
Object.keys(TypeMessages).forEach((value: string, index: number) => {
|
2020-10-19 21:04:16 +02:00
|
|
|
const typeMessageInstance: TypeMessageInterface = (new valueTypeMessageTab[index]() as TypeMessageInterface);
|
2020-10-19 19:32:47 +02:00
|
|
|
this.typeMessages.set(value.toLowerCase(), typeMessageInstance);
|
|
|
|
});
|
|
|
|
this.initialise();
|
|
|
|
}
|
|
|
|
|
2020-10-19 21:04:16 +02:00
|
|
|
initialise() {
|
2020-10-19 19:32:47 +02:00
|
|
|
//receive signal to show message
|
|
|
|
this.Connection.receiveUserMessage((type: string, message: string) => {
|
2021-01-25 14:10:16 +01:00
|
|
|
const typeMessage = this.showMessage(type, message);
|
|
|
|
|
|
|
|
//listener on banned receive message
|
|
|
|
if(typeMessage instanceof Banned) {
|
|
|
|
for (const callback of this.receiveBannedMessageListener) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
2020-10-19 19:32:47 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-19 21:04:16 +02:00
|
|
|
showMessage(type: string, message: string) {
|
|
|
|
const classTypeMessage = this.typeMessages.get(type.toLowerCase());
|
|
|
|
if (!classTypeMessage) {
|
2020-10-19 19:32:47 +02:00
|
|
|
console.error('Message unknown');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
classTypeMessage.showMessage(message);
|
2021-01-25 14:10:16 +01:00
|
|
|
return classTypeMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
setReceiveBanListener(callback: Function){
|
|
|
|
this.receiveBannedMessageListener.add(callback);
|
2020-10-19 19:32:47 +02:00
|
|
|
}
|
2020-10-19 21:04:16 +02:00
|
|
|
}
|