partey_workadventure/front/src/Connexion/AdminMessagesService.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-09-06 14:27:54 +02:00
import { Subject } from "rxjs";
import type { BanUserMessage, SendUserMessage } from "../Messages/generated/messages_pb";
export enum AdminMessageEventTypes {
2021-09-06 14:27:54 +02:00
admin = "message",
audio = "audio",
ban = "ban",
banned = "banned",
}
interface AdminMessageEvent {
2021-09-06 14:27:54 +02:00
type: AdminMessageEventTypes;
text: string;
//todo add optional properties for other event types
}
//this class is designed to easily allow communication between the RoomConnection objects (that receive the message)
//and the various objects that may render the message on screen
class AdminMessagesService {
private _messageStream: Subject<AdminMessageEvent> = new Subject();
public messageStream = this._messageStream.asObservable();
constructor() {
2021-09-06 14:27:54 +02:00
this.messageStream.subscribe((event) => console.log("message", event));
}
2021-09-06 14:27:54 +02:00
onSendusermessage(message: SendUserMessage | BanUserMessage) {
this._messageStream.next({
type: message.getType() as unknown as AdminMessageEventTypes,
text: message.getMessage(),
2021-09-06 14:27:54 +02:00
});
}
}
export const adminMessagesService = new AdminMessagesService();