Skip to content

Detects if online/offline i.e connect to the server or not.

Notifications You must be signed in to change notification settings

koppathachan/offlineTs

 
 

Repository files navigation

offlinets

offlinets will check service availability by pinging it.

Usage

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

This syntax uses the DefaultPingService.

@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() {
    }
}

User implemented PingService.

@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() {
    }
}

StateType is as follows

export enum StateType {
    ONLINE,
    OFFLINE
}

About

Detects if online/offline i.e connect to the server or not.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%