Skip to content

arteg/connect_tester

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

connect_tester.js

Testing connection of clientside application.

Sometimes you need to know if your user has slow connection and you want to suggest gracefully degraded version of your app. connect_tester.js downloads a file from server once in a while to allow you to determine how long did it take to make assumptions on how slow it is.

Usage

Create tester:

var tester = new ConnectTester();

Set image url for testing, a callback for processing test results and run:

tester.test('xxx.png').onChange(cb).run();

You can specify the timeout in milliseconds for the permanent checking:

tester.test('xxx.png').every(40000).onChange(cb).run();

Enabling debug mode:

tester.test('xxx.png').every(40000).onChange(cb).debug().run();

Сallback for processing test takes a delay getting the picture in milliseconds. Based on it, you can calculate the download bandwidth:

function(duration){
    var kbps = (image_size_in_bytes * 8) / (duration / 1000) / 1024;
}

Full example

(new ConnectTester)
    .test('xxx.png')
    .every(40000)
    .debug()
    .run()
    .onChange(function(duration){
        var kbps = (image_size_in_bytes * 8) / (duration / 1000) / 1024;
        // ...
    });

About

Testing connect for clientside application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published