2021-03-01 17:47:00 +01:00
|
|
|
import {Subject} from "rxjs";
|
2021-05-12 09:13:25 +02:00
|
|
|
import type {BanUserMessage, SendUserMessage} from "../Messages/generated/messages_pb";
|
2021-03-01 17:47:00 +01:00
|
|
|
|
|
|
|
export enum AdminMessageEventTypes {
|
|
|
|
admin = 'message',
|
|
|
|
audio = 'audio',
|
|
|
|
ban = 'ban',
|
2021-04-19 20:19:40 +02:00
|
|
|
banned = 'banned',
|
2021-03-01 17:47:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
interface AdminMessageEvent {
|
|
|
|
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();
|
2021-05-12 09:13:25 +02:00
|
|
|
|
2021-03-01 17:47:00 +01:00
|
|
|
constructor() {
|
|
|
|
this.messageStream.subscribe((event) => console.log('message', event))
|
|
|
|
}
|
2021-05-12 09:13:25 +02:00
|
|
|
|
2021-03-11 02:22:05 +01:00
|
|
|
onSendusermessage(message: SendUserMessage|BanUserMessage) {
|
2021-03-01 17:47:00 +01:00
|
|
|
this._messageStream.next({
|
|
|
|
type: message.getType() as unknown as AdminMessageEventTypes,
|
|
|
|
text: message.getMessage(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 09:13:25 +02:00
|
|
|
export const adminMessagesService = new AdminMessagesService();
|