Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
d8044507ed | |||
b9380be999 | |||
1b9c354d69 | |||
a8f4ecf98f | |||
6350088d2a | |||
10ef1d0455 | |||
f709238e50 | |||
49940635d5 | |||
ec4121cbcf | |||
ea9a2572f9 | |||
cc0f1c40a6 | |||
9da04081e4 | |||
4ae0925043 | |||
4e862e784b |
5535
package-lock.json
generated
5535
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnetwork",
|
"name": "@pushrocks/smartnetwork",
|
||||||
"version": "1.1.21",
|
"version": "2.0.5",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "network diagnostics",
|
"description": "network diagnostics",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -9,24 +9,24 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"tslint": "^5.20.1",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@pushrocks/smartstring": "^3.0.18",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
"@types/default-gateway": "^3.0.1",
|
"@types/default-gateway": "^3.0.1",
|
||||||
"default-gateway": "^5.0.5",
|
|
||||||
"isopen": "^1.3.0",
|
"isopen": "^1.3.0",
|
||||||
"public-ip": "^4.0.2",
|
"public-ip": "^4.0.3",
|
||||||
"speedtest-net": "^1.6.0",
|
"speed-cloudflare-cli": "^2.0.3",
|
||||||
"systeminformation": "^4.26.10"
|
"speedtest-net": "^2.1.1",
|
||||||
|
"systeminformation": "^5.6.12"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
@ -9,13 +9,13 @@ tap.test('should create a valid instance of SmartNetwork', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should perform a speedtest', async () => {
|
tap.test('should perform a speedtest', async () => {
|
||||||
let result = await testSmartNetwork.getSpeed();
|
const result = await testSmartNetwork.getSpeed();
|
||||||
console.log(`Download speed for this instance is ${result.speeds.download}`);
|
// console.log(`Download speed for this instance is ${result.download.bandwidth}`);
|
||||||
console.log(`Upload speed for this instance is ${result.speeds.upload}`);
|
// console.log(`Upload speed for this instance is ${result.download.bandwidth}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should determine wether a port is free', async () => {
|
tap.test('should determine wether a port is free', async () => {
|
||||||
await expect(testSmartNetwork.isLocalPortAvailable(8080)).to.eventually.be.true;
|
await expect(testSmartNetwork.isLocalPortUnused(8080)).to.eventually.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should scan a port', async () => {
|
tap.test('should scan a port', async () => {
|
||||||
|
@ -1,34 +1,31 @@
|
|||||||
import * as plugins from './smartnetwork.plugins';
|
import * as plugins from './smartnetwork.plugins';
|
||||||
|
|
||||||
export interface ISpeedtestData {
|
export interface ISpeedtestData {
|
||||||
speeds: {
|
timestamp: Date;
|
||||||
download: number;
|
ping: { jitter: number; latency: number };
|
||||||
upload: number;
|
download: { bandwidth: number; bytes: number; elapsed: number };
|
||||||
originalDownload: number;
|
upload: { bandwidth: number; bytes: number; elapsed: number };
|
||||||
originalUpload: number;
|
packetLoss: number;
|
||||||
};
|
isp: string;
|
||||||
client: {
|
interface: {
|
||||||
ip: string;
|
internalIp: string;
|
||||||
lat: number;
|
name: string;
|
||||||
lon: number;
|
macAddr: string;
|
||||||
isp: string;
|
isVpn: false;
|
||||||
isprating: string;
|
externalIp: string;
|
||||||
rating: number;
|
|
||||||
ispdlavg: number;
|
|
||||||
ispulavg: number;
|
|
||||||
};
|
};
|
||||||
server: {
|
server: {
|
||||||
host: string;
|
id: number;
|
||||||
lat: number;
|
name: string;
|
||||||
lon: number;
|
|
||||||
location: string;
|
location: string;
|
||||||
country: string;
|
country: string;
|
||||||
cc: string;
|
host: string;
|
||||||
sponsor: string;
|
port: number;
|
||||||
distance: number;
|
ip: string;
|
||||||
distanceMi: number;
|
};
|
||||||
ping: number;
|
result: {
|
||||||
id: string;
|
id: string;
|
||||||
|
url: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,16 +37,9 @@ export class SmartNetwork {
|
|||||||
* get network speed
|
* get network speed
|
||||||
* @param measurementTime
|
* @param measurementTime
|
||||||
*/
|
*/
|
||||||
public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
|
public async getSpeed() {
|
||||||
const done = plugins.smartpromise.defer<ISpeedtestData>();
|
const test = null;
|
||||||
const test = plugins.speedtestNet({ maxTime: measurementTime });
|
return test;
|
||||||
test.on('data', (data) => {
|
|
||||||
done.resolve(data);
|
|
||||||
});
|
|
||||||
test.on('error', (err) => {
|
|
||||||
done.reject(err);
|
|
||||||
});
|
|
||||||
return await done.promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +47,7 @@ export class SmartNetwork {
|
|||||||
* note: false also resolves with false as argument
|
* note: false also resolves with false as argument
|
||||||
* @param port
|
* @param port
|
||||||
*/
|
*/
|
||||||
public async isLocalPortAvailable(port: number): Promise<boolean> {
|
public async isLocalPortUnused(port: number): Promise<boolean> {
|
||||||
const doneIpV4 = plugins.smartpromise.defer<boolean>();
|
const doneIpV4 = plugins.smartpromise.defer<boolean>();
|
||||||
const doneIpV6 = plugins.smartpromise.defer<boolean>();
|
const doneIpV6 = plugins.smartpromise.defer<boolean>();
|
||||||
const net = await import('net'); // creates only one instance of net ;) even on multiple calls
|
const net = await import('net'); // creates only one instance of net ;) even on multiple calls
|
||||||
|
@ -12,7 +12,6 @@ export { smartpromise, smartstring };
|
|||||||
// @third party scope
|
// @third party scope
|
||||||
import isopen from 'isopen';
|
import isopen from 'isopen';
|
||||||
import publicIp from 'public-ip';
|
import publicIp from 'public-ip';
|
||||||
import speedtestNet from 'speedtest-net';
|
|
||||||
import * as systeminformation from 'systeminformation';
|
import * as systeminformation from 'systeminformation';
|
||||||
|
|
||||||
export { isopen, publicIp, speedtestNet, systeminformation };
|
export { isopen, publicIp, systeminformation };
|
||||||
|
Reference in New Issue
Block a user