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() { ngOnInit() {
this.websocketService.connect(); this.websocketService.connect();
this.websocketService.observeKey<MessagesMessage>('message').subscribe( this.websocketService.observeKey<MessagesMessage>('message').subscribe(
(event) => { (event) => this.handleMessage(event.data)
this.messages.push(event.data); );
event.data.message = this.convert(event.data.message);
this.changeDetectorRef.detectChanges();
});
this.websocketService.observeKey<CommandMessage>('messagecontrol').subscribe( this.websocketService.observeKey<CommandMessage>('messagecontrol').subscribe(
(event) => { (event) => this.command_handlers[event.data.command](event.data)
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) { convert(text: string) {