A lightweight Angular 2+ service for checking internet speed
- Try out the demo to see it in action!
- Visit my website for other cool projects!
npm install ng-speed-test --save
-
Import
SpeedTestModule
by adding the following to your parent module (i.e.app.module.ts
):import { SpeedTestModule } from 'ng-speed-test'; @NgModule({ ... imports: [ SpeedTestModule, ... ], ... }) export class AppModule {}
- Checkout the demo and it's code for more examples.
import {SpeedTestService} from 'ng-speed-test';
@Injectable()
export class TechCheckService {
constructor(
private speedTestService:SpeedTestService
) {
this.speedTestService.getMbps().subscribe(
(speed) => {
console.log('Your speed is ' + speed);
}
);
}
}
import {SpeedTestService} from 'ng-speed-test';
@Injectable()
export class TechCheckService {
constructor(
private speedTestService:SpeedTestService
) {
this.speedTestService.getMbps(
{
iterations: 10,
file: {
path: 'my-custom-image.png',
size: 2048
},
retryDelay: 1500,
}
).subscribe(
(speed) => {
console.log('Your speed is ' + speed);
}
);
}
}
import {SpeedTestService} from 'ng-speed-test';
@Injectable()
export class TechCheckService {
constructor(
private speedTestService:SpeedTestService
) {
this.speedTestService.isOnline().subscribe(
(isOnline) => {
if (isOnline === false) {
console.log('Network unavailable.');
}
}
);
}
}
getBps()
- Get the current internet speed in Bps (bits per second).getKbps()
- Get the current internet speed in Kbps (kilobits per second).getMbps()
- Get the current internet speed in Mbps (megabits per second).isOnline()
- Check if the network is available.
file
- see File Settings (below)iterations
- (default: 3) The number of speed readings to take for the average. Increase iterations the more accurate results, decrease iterations for faster results.retryDelay
- (default: 500) The number of milliseconds to wait before the next iteration after a network error
[path]
- (default: ~5Mb image stored on GitHub) The URL where to download an image for determining internet speed.- Other Included Paths
- ~500 KB (408949 kb) - https://raw.githubusercontent.com/jrquick17/ng-speed-test/02c59e4afde67c35a5ba74014b91d44b33c0b3fe/demo/src/assets/500kb.jpg
- ~1 MB (1197292 kb)- https://raw.githubusercontent.com/jrquick17/ng-speed-test/02c59e4afde67c35a5ba74014b91d44b33c0b3fe/demo/src/assets/1mb.jpg
- ~5 MB (4952221 kb) (default) - https://raw.githubusercontent.com/jrquick17/ng-speed-test/02c59e4afde67c35a5ba74014b91d44b33c0b3fe/demo/src/assets/5mb.jpg
- ~13 MB (13848150 kb) - https://raw.githubusercontent.com/jrquick17/ng-speed-test/02c59e4afde67c35a5ba74014b91d44b33c0b3fe/demo/src/assets/13mb.jpg
- Other Included Paths
[size]
- (default: ~5Mb) The size of the image at the path (in bits)[shouldBustCache]
(default: true) Append GET variable to bust browser cache
If you find any issues feel free to open a request in the Issues tab. If I have the time I will try to solve any issues but cannot make any guarantees. Feel free to contribute yourself.
- Run
npm install
to get packages required for the demo and then runnpm run demo
to run locally.
- Run
npm run docs:build
- Update version
package.json
files in both the root anddist/
directory following Semantic Versioning (2.0.0).
- Run
npm run build
from root.
- Run
npm run build:link
in root directory - Run
npm link ng-speed-test
indemo/
or any external project - Run Demo See: Demo
- When done, run
npm unlink
indemo/
or any external project
- Run
npm run shipit
- Add updates to
CHANGELOG.md
in root.