npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

offlinets

v3.2.4-2

Published

ping a service to check if it is up

Downloads

32

Readme

offlinets

offlinets will check availability of a service by pinging it. An example would be to detect the internet availability in the browser. run npm run demo and open http://localhost:3000 to see this in action.

Version 3

Usage

Define any class that should be notified and updated when the state of service changes. The class should have a member updateState(state: StateType, response: Response|Error). updateState is called with StateType as well as the Response.

ServiceStatus

An instance of ServiceStatus is created like this:

let serviceStatus = new ServiceStatus(new PingService());

ServiceStatus mandatorily takes a PingService as argument. PingService.ping() will be called to check service availability. PingService interface looks like this:

interface PingService {
    ping: () => Promise<Response>;
}

This ServiceStatus class has an exported member to get the response. It looks like this:

 get Response(): Response | Error {
        return this.response || new Response();
    }
Observer interface:
To annotate the class with the Observe decorator in serviceStatus instance, refer version-2(usage) context.
interface Observer {
    updateState: (state: StateType, response?: Response|Error) => Promise<any>;
    ObserverId?: number;
}

SyncService

To start the period ping, refer version-2(usage) context.
Retry

Start retrying when sync fails by calling:

syncService.retry(3);// 3 is number for maxRetry.

Version 3 exposes a getter method for a Promise that resolves to SyncStatus.. It looks like this:

get SyncStatus(): Promise<SyncStatus> {
    }

Version 2

Usage

Define any class that should be notified and updated when the state of service changes. The class should have a member updateState(state: StateType). Create an instance of ServiceStatus like:

let serviceStatus = new ServiceStatus(new PingService());

ServiceStatus mandatorily takes a PingService as argument. PingService.ping() will be called to check service availability. PingService interface looks like this:

interface PingService {
    ping: () => Promise<boolean>;
}

Annotate the class with the Observe decorator in serviceStatus instance:

@serviceStatus.Observe
export class SampleObserver {
    state: number = 0;

    //this function will be called when state of the system changes.
    updateState(state: StateType) {
        this.state = 999;
    }
    constructor() {
    }
}

Start the period ping by calling:

serviceStatus.startPing(1500);// 1500 ms interval period.

Provide an optional API parameter if in case want ping other than origin, if optional API is not privided it will ping the origin:

serviceStatus.startPing(1500, "https://localhost:3000/favicon.ico");// 1500 ms interval period.

Using with Javascript.

var TestObserver = serviceStatus.Observe(function () {
    this.state = 0;
    this.updateState = function () {
        this.state = 999;
        return true;
    }
})

exports.TestObserver = TestObserver;

Sync Service

Version 2 provides a service can be used to synchronize local data with remote server

Basic Usage
import {SyncService, SyncServiceStatus} from "sync";
let syncService = new SyncService(new OfflineDataService(), maxRetry);
SyncServiceStatus.startPing(1500);
OfflineDataService interface:
interface OfflineDataService {
    //implementation should sync data and return true for success.
    //false for everything else.
    sync(): Promise<boolean> {
    }

    //implement this to check if data exists, 
    //it would be good if this check was fast.
    hasData(): Promise<boolean> {
    }
}
maxRetry

Set this value to allow number of retries when sync fails. by default its set to Infinity

Version 1

Usage

Define any class that should be notified and updated when the state of service changes. The class should have a member updateState(state: StateType) 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(state: StateType) {
        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
}

Core Contributors

Feel free to reach out to any of the core contributors with your questions or concerns. We will do our best to respond in a timely manner.

IntimeTec Syed Fayaz Nandita Khemnani Akhil Sasidharan