Skip to content

jrquick17/ng-speed-test

Repository files navigation

ng-speed-test

npm npm npm

Index

About

A lightweight Angular 2+ service for checking internet speed

Setup

Install

npm install ng-speed-test --save

Import module

  • 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 {}
    

Functionality

Check Internet Speed

  • 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);
      }
    );
  }
}

Check Internet Speed w/ Custom Settings

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);
      }
    );
  }
}

Check If Online

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.');
        }
      }
    );
  }
}

Functions

  • 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.

Settings

  • 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

File Settings

Contributing

Thanks

Issues

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.

Release

Demo

  • Run npm install to get packages required for the demo and then run npm run demo to run locally.

Generate Docs

  • Run npm run docs:build

Update Version

Build

  • Run npm run build from root.

Test

  • Run npm run build:link in root directory
  • Run npm link ng-speed-test in demo/ or any external project
  • Run Demo See: Demo
  • When done, run npm unlink in demo/ or any external project

NPM Release

  • Run npm run shipit

Update Changelog

  • Add updates to CHANGELOG.md in root.

About

A light weight Angular 2+ library for checking internet speed

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •