I am trying to perform an action as soon as the service i created is connected to his server. Currently im simply saving a connected: boolean
which changes state on connection and connection lost, and return it as an observable.
With the subscribe i am only able to retrieve the initial state of the observable. The subscribe does not fire when the boolean changes its value (which it does).
Any help is appreciated.
app.component.ts (subscription)
ngOnInit() {
this.moduleService.isConnected().subscribe(value => console.log(value));
}
module.service.ts (injected in component)
isConnected(): Observable<boolean> {
return of(this._mqttApi.isConnected());
}
mqttApi.ts (boolean changes here)
connected: boolean = false;
onConnect(){
connected = true;
}
onConnectionLost(){
connected = false
}
public isConnected(): boolean{
return this.connected;
}