offlinets will check service availability by pinging it.
Define any class that should be notified and updated when the state of service changes. Annotate it with @Observe() passing in the period of ping interval and a PingService as config. Default implementation will be provided if PingService is not found.
PingService interface looks like this:
interface PingService {
ping: () => Promise<boolean>;
}
@Observe({
period: 1000
})
export class SampleObserver {
state: number = 0;
//this function will be called when state of the system changes.
updateState() {
this.state = 999;
}
constructor() {
}
}
@Observe({
period: 1000,
ping: new PingService()
})
export class SampleObserver {
state: number = 0;
//this function will be called when state of the system changes.
async updateState(state: StateType) {
this.state = 999;
return true
}
constructor() {
}
}
export enum StateType {
ONLINE,
OFFLINE
}