react-native-connectivity-tracker
Advanced tools
Comparing version 0.0.3 to 1.0.0
25
index.js
@@ -15,3 +15,4 @@ /* eslint-disable react/no-this-in-sfc */ | ||
tryConnection() { | ||
NetInfo.isConnected.fetch().then(this.handleConnectivityChange.bind(this)); | ||
return NetInfo.isConnected.fetch() | ||
.then(this.handleConnectivityChange.bind(this)) | ||
}, | ||
@@ -30,3 +31,3 @@ | ||
) { | ||
this.verifyServersAreUp().then((areUp) => { | ||
return this.verifyServersAreUp().then((areUp) => { | ||
// now that we've verified wether we're up or not | ||
@@ -39,2 +40,3 @@ if (this.shouldDispatchEvent(timestampOfChange)) { | ||
this.dispatchConnectivityChanged(newValue, timestampOfChange); | ||
return newValue; | ||
} | ||
@@ -46,2 +48,3 @@ }); | ||
} | ||
return isConnected; | ||
}, | ||
@@ -63,9 +66,8 @@ | ||
if (this.mOpts.verifyServersAreUp) { // and we have a verification callback/promise | ||
if (typeof this.mOpts.verifyServersAreUp === 'function') { // if it's a callback | ||
const verification = this.mOpts.verifyServersAreUp(); | ||
if (typeof(verification) === 'boolean') { | ||
return verification | ||
} else if (verification.then != null) { // else if it's a promise | ||
// verify servers are up | ||
return this.mOpts.verifyServersAreUp(); | ||
} | ||
if (this.mOpts.verifyServersAreUp.then != null) { // else if it's a promise | ||
// verify servers are up | ||
return this.mOpts.verifyServersAreUp | ||
return verification | ||
.then(res => res) | ||
@@ -79,2 +81,3 @@ .catch((e) => { | ||
} | ||
if (this.mOpts.onError) { | ||
@@ -115,2 +118,8 @@ this.mOpts.onError( | ||
).catch((e) => { | ||
if (e | ||
&& e.message | ||
&& e.message.indexOf | ||
&& e.message.indexOf('Network request failed') !== -1) { | ||
return false; | ||
} | ||
if (this.mOpts.onError) { | ||
@@ -117,0 +126,0 @@ this.mOpts.onError(e); |
{ | ||
"name": "react-native-connectivity-tracker", | ||
"version": "0.0.3", | ||
"version": "1.0.0", | ||
"description": "Checks wether the connection is valid", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,3 +29,3 @@ ## react-native-connectivity-tracker | ||
onError: msg => console.log(msg), | ||
// verifyServersAreUp: store.dispatch(checkOurServersAreUp()), | ||
// verifyServersAreUp: () => store.dispatch(checkOurServersAreUp()), | ||
}); | ||
@@ -44,3 +44,3 @@ ``` | ||
| **onError** | function | - | Pass a function here if you want to log errors. | | ||
| **verifyServersAreUp** | Promise or function | - | This overrides the default verification method. Feel free to disregard this, unless want to use your own verification method, instead of relying to google responces. | | ||
| **verifyServersAreUp** | function | - | This overrides the default verification method. Feel free to disregard this, unless want to use your own verification method, instead of relying to google responces. This function can return either a result (true or false) or a Promise | | ||
@@ -47,0 +47,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8528
115
1