Refactor handling of messages

This commit is contained in:
Kristóf Tóth 2018-06-25 09:59:45 +02:00
parent 6ee58da7e4
commit a825841d0e

View File

@ -32,15 +32,17 @@ export class MessagesComponent implements OnInit {
ngOnInit() {
this.websocketService.connect();
this.websocketService.observeKey<MessagesMessage>('message').subscribe(
(event) => {
this.messages.push(event.data);
event.data.message = this.convert(event.data.message);
this.changeDetectorRef.detectChanges();
});
(event) => this.handleMessage(event.data)
);
this.websocketService.observeKey<CommandMessage>('messagecontrol').subscribe(
(event) => {
this.command_handlers[event.data.command](event.data);
});
(event) => this.command_handlers[event.data.command](event.data)
);
}
handleMessage(data: MessagesMessage) {
data.message = this.convert(data.message);
this.messages.push(data);
this.changeDetectorRef.detectChanges();
}
convert(text: string) {