1.0.6 • Published 3 years ago

netest v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Netest

NPM License

NPM

Netest is a Javascript library for testing internet speed in the browser. A speed check is conducted by downloading image(s), and using download time in order to get the average download speed, multiple checks could be made with different parameters.

Installation

Use npm to install Netest.

npm install netest

Usage

Conduct a single check

const netest = require("netest")

const netestOptions = {
   slowSpeedThreshold: 100,
   numOfChecks: 3,
   failIfTooLong: true,
   timeUntilLoadFailure: 60000,
   loadFailureCheckInterval: 2000,
   imageSource: "https://upload.wikimedia.org/wikipedia/commons/b/b9/Pizigani_1367_Chart_1MB.jpg",
   imageSize: 1040
};

netest(netestOptions)
.then((result) => {
   if (!result.isSlow) console.log("Your internet is great!");
})
.catch((error) => {
   if (error.hasFailed) console.log("Too bad, your internet sucks...")
});

You can also use it to run regular speed checks on the background

let speedCheckInterval = 3*60*1000; // 1 check per 3 minutes

let checkInterval = new BehaviorSubject(speedCheckInterval);
let speedChecks = checkInterval.pipe(
   switchMap(i => interval(i)),
   tap(() => {
      netest(netestOptions)
      .then((result) => { if (!result.isSlow) console.log("Your internet is great!") })
      .catch((error) => { if (error.hasFailed) console.log("Too bad, your internet sucks...") })
      .finally(() => checkInterval.next(speedCheckInterval)); // Reset the timer at end
   })
).subscribe();

Options

FieldDescriptionTypeRequired
slowSpeedThresholdSlow connection speed threshold in kb/s, any lower and user's connection is considered slowNumericYes
numOfChecksNumber of checks conducted and averagedNumericYes
failIfTooLongFails the tests if a check takes too longBooleanYes
timeUntilLoadFailureDuration threshold of a single check for test failure in msNumericYes
loadFailureCheckIntervalHow often should the failure threshold check be conducted in msNumericYes
imageSourceSource of the image to be downloaded for the speed checksStringYes
imageSizeSize of the speed checks image in KbNumericYes

Check Completion Outputs

FieldDescriptionType
isSlowIndicates that the internet speed is slow, when the speed precedes slowSpeedThresholdNumeric
kbPerSecAverage internet speedNumeric
averageLoadTimeAverage completion time of all checksBoolean
totalLoadTimeTotal completion time of all checksNumeric

Check Failure Outputs

FieldDescriptionType
hasFailedIndicates that a check has failed, when timeUntilLoadFailure threshold has passedNumeric

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago