partey_workadventure/front/src/Administration/UserMessageManager.ts

30 lines
1.3 KiB
TypeScript
Raw Normal View History

import { AdminMessageEventTypes, adminMessagesService } from "../Connexion/AdminMessagesService";
2021-12-24 12:15:54 +01:00
import { textMessageStore } from "../Stores/TypeMessageStore/TextMessageStore";
import { soundPlayingStore } from "../Stores/SoundPlayingStore";
import { UPLOADER_URL } from "../Enum/EnvironmentVariable";
2021-12-24 12:15:54 +01:00
import { banMessageStore } from "../Stores/TypeMessageStore/BanMessageStore";
class UserMessageManager {
receiveBannedMessageListener!: Function;
constructor() {
adminMessagesService.messageStream.subscribe((event) => {
if (event.type === AdminMessageEventTypes.admin) {
2021-12-24 12:15:54 +01:00
textMessageStore.addMessage(event.text);
} else if (event.type === AdminMessageEventTypes.audio) {
soundPlayingStore.playSound(UPLOADER_URL + event.text);
} else if (event.type === AdminMessageEventTypes.ban) {
2021-12-24 12:15:54 +01:00
banMessageStore.addMessage(event.text);
} else if (event.type === AdminMessageEventTypes.banned) {
2021-12-24 12:15:54 +01:00
banMessageStore.addMessage(event.text);
this.receiveBannedMessageListener();
2021-01-25 14:10:16 +01:00
}
});
2021-01-25 14:10:16 +01:00
}
setReceiveBanListener(callback: Function) {
this.receiveBannedMessageListener = callback;
}
}
export const userMessageManager = new UserMessageManager();