ng-speed-test
TypeScript icon, indicating that this package has built-in type declarations

2.6.1 • Public • Published

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.

Package Sidebar

Install

npm i ng-speed-test

Weekly Downloads

1,295

Version

2.6.1

License

MIT

Unpacked Size

61.6 kB

Total Files

19

Last publish

Collaborators

  • jrquick