GithubHelp home page GithubHelp logo

fe-liupeng / sp-isoffline Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lianglei-git/sp-isoffline

0.0 0.0 0.0 3 KB

is online and offline on nodejs; 检测网络状态(nodejs)

JavaScript 100.00%

sp-isoffline's Introduction

sp-isoffline

  1. is online on nodejs by ping hosts: www.baidu.com, weixin.qq.com...
  2. offline to online on nodejs

Install

npm install sp-isoffline or yarn add sp-isoffline

api

isonline:

网络是否处于在线状态(一次性( one-off )) code:

import {isonline} from 'sp-isoffline'

/*
 * dnses: [...]
 */
isonline().then(status => {
    if(status) {
        // online
    }else {
        // offline
    }
})

offlineListener:

网络监听器, 默认三秒 轮询 code:

offlineListener({
    time: 1000, // 间隔
    // interval: 9, // 次数
    offline(callback) { // 网络断开
        console.log('网络断开')
        callback(({ status }) => {
            if (status) console.log('联网成功')
            else console.log('网络连接失败')
        })
    },
    online({ status }) { // 网络正常情况下
        if (status) console.log('网络正常')
    }
})

sp-isoffline's People

Contributors

lianglei-git avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.