mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2024-12-05 02:31:33 +00:00
Refactor handling of messages
This commit is contained in:
parent
6ee58da7e4
commit
a825841d0e
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user