A lightweight Angular 2+ service for checking internet speed
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 {}
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.
[size]
- (default: ~5Mb) The size of the image at the path (in bits)[shouldBustCache]
(default: true) Append GET variable to bust browser cacheIf 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.
npm install
to get packages required for the demo and then run npm run demo
to run locally.npm run docs:build
package.json
files in both the root and dist/
directory following Semantic Versioning (2.0.0).npm run build
from root.npm run build:link
in root directorynpm link ng-speed-test
in demo/
or any external projectnpm unlink
in demo/
or any external projectnpm run shipit
CHANGELOG.md
in root.