Code Monkey home page Code Monkey logo

Comments (14)

SamVerschueren avatar SamVerschueren commented on June 1, 2024

Are you sure you check the correct parameter in the callback? The first is most likely the error (which will be undefined).

from is-online.

Artem-Schander avatar Artem-Schander commented on June 1, 2024

yep, I'm sure.
Here is my code:

isReachable('google.com:80', (err, reachable) => {
    console.log(reachable);
});

or

isOnline(function(err, online) {
    console.log(online);
});

from is-online.

SamVerschueren avatar SamVerschueren commented on June 1, 2024

And what does err return?

From the docs

Same as above except the callback doesn't have an error parameter.

Not sure if err is undefined or the first param actually is the result.

from is-online.

Artem-Schander avatar Artem-Schander commented on June 1, 2024

I've also tried the following while connected / disconnected:

isOnline(function(online) {
    console.log(online);
});

Both results were false

from is-online.

Artem-Schander avatar Artem-Schander commented on June 1, 2024

BTW. I'm including it via import isOnline from 'is-online'; and compile it then with babel.
But that should not be the reason for this issue. I hope.

All the other ES6 stuff works well.

from is-online.

silverwind avatar silverwind commented on June 1, 2024

Neither is-online nor is-reachable are capable of returning undefined to the callback. Try this in the REPL (the null true are the callback args):

$ node
> require('is-reachable')('google.com', console.log)
undefined
> null true

from is-online.

Artem-Schander avatar Artem-Schander commented on June 1, 2024

@silverwind
GET file://google.com/favicon.ico?1457219323579 net::ERR_FILE_NOT_FOUND

maybe it's because of electron ?

from is-online.

silverwind avatar silverwind commented on June 1, 2024

You're getting the browser API: https://github.com/sindresorhus/is-reachable/blob/master/browser.js

As to why, I'm not sure, I thought electron scripts should get the node version?

from is-online.

jdrew1303 avatar jdrew1303 commented on June 1, 2024

Hey I ran into the same issue. It may be because there is no main property set in the package.json. Also if you're using browserify or webpack they will fallback to browser instead. Great little lib though. 😃

Hope this helps.

from is-online.

sindresorhus avatar sindresorhus commented on June 1, 2024

It may be because there is no main property set in the package.json.

Proof? Electron handles no "main" just fine, which is optional if you have an index.js file.

from is-online.

jdrew1303 avatar jdrew1303 commented on June 1, 2024

@sindresorhus I experienced a similar issue and at the time was investigating that avenue. It was a maybe rather than a definite.

The actual issue is that the documentation is wrong on the signature of the function.

The first item is the online status and not an error. Thats why they're getting undefined.

isOnline((online) => {
$scope.isOnline = online;
});

should work as expected.

from is-online.

silverwind avatar silverwind commented on June 1, 2024

I'd say the documentation is right. Both is-online and is-reachable have:

Browser API

Same as above except the callback doesn't have an error parameter.

from is-online.

silverwind avatar silverwind commented on June 1, 2024

The issue here is still, that electron should never get browser.js in first place. Maybe someone affected can test if adding main resolves this.

from is-online.

Artem-Schander avatar Artem-Schander commented on June 1, 2024

in fact electron runs two processes

  1. main process (node server)
  2. renderer (chromium browser / client)

so (it is how it should be) if you run it from the renderer it's the browser api.

from is-online.

Related Issues (20)

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.