mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-04-03 11:52:40 +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() {
|
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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user