Finishes basic websocket-handler.service.ts

This commit is contained in:
GloriousCode
2017-09-12 19:46:57 +10:00
parent 6d02dfe057
commit dfc6b0e392
6 changed files with 64 additions and 34 deletions

View File

@@ -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>

View File

@@ -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);
}
}