mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 23:16:51 +00:00
Finishes basic websocket-handler.service.ts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<form class="example-form">
|
||||
<md-form-field class="example-full-width">
|
||||
<input mdInput placeholder="Favorite food" value="Sushi">
|
||||
<input mdInput placeholder="Favorite food" value="{{Settings?.Name}}">
|
||||
</md-form-field>
|
||||
</form>
|
||||
@@ -7,10 +7,42 @@ import { WebsocketHandlerService } from './../../services/websocket-handler/webs
|
||||
styleUrls: ['./settings.component.scss']
|
||||
})
|
||||
export class SettingsComponent implements OnInit {
|
||||
private settings:any = null;
|
||||
private ws: WebsocketHandlerService;
|
||||
|
||||
constructor() { }
|
||||
constructor(private websocketHandler: WebsocketHandlerService) {
|
||||
this.ws = websocketHandler;
|
||||
this.ws.messages.subscribe(msg => {
|
||||
if(msg.Event == "GetConfig") {
|
||||
this.settings = msg.data;
|
||||
} else if (msg.Event == "SaveConfig") {
|
||||
//something!
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getSettings();
|
||||
}
|
||||
|
||||
private getSettingsMessage = {
|
||||
Event:'GetConfig',
|
||||
data:null
|
||||
};
|
||||
|
||||
private getSettings():void {
|
||||
console.log('new message from client to websocket: ', this.getSettingsMessage);
|
||||
this.ws.messages.next(this.getSettingsMessage);
|
||||
this.resendMessageIfPageRefreshed();
|
||||
}
|
||||
|
||||
private resendMessageIfPageRefreshed():void {
|
||||
setInterval(()=> {
|
||||
if(this.settings === null) {
|
||||
console.log('Settings hasnt been set. Trying again');
|
||||
this.getSettings();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user