Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
1b9c354d69 | |||
a8f4ecf98f | |||
6350088d2a | |||
10ef1d0455 | |||
f709238e50 | |||
49940635d5 |
7
package-lock.json
generated
7
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnetwork",
|
"name": "@pushrocks/smartnetwork",
|
||||||
"version": "2.0.1",
|
"version": "2.0.4",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -3109,6 +3109,11 @@
|
|||||||
"integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=",
|
"integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/speedtest-net": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@types%2fspeedtest-net/-/speedtest-net-2.1.0.tgz",
|
||||||
|
"integrity": "sha512-a6P3s2qOWU08yu/fk/xyswqRlDyeTmg5RMwedC0h1ZbH2d2iqYVATUXX/Jgl4P5hs12uhj0AQCEZlgVbVXSfKQ=="
|
||||||
|
},
|
||||||
"@types/through2": {
|
"@types/through2": {
|
||||||
"version": "2.0.36",
|
"version": "2.0.36",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fthrough2/-/through2-2.0.36.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fthrough2/-/through2-2.0.36.tgz",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnetwork",
|
"name": "@pushrocks/smartnetwork",
|
||||||
"version": "2.0.1",
|
"version": "2.0.4",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "network diagnostics",
|
"description": "network diagnostics",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"@pushrocks/smartpromise": "^3.1.3",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@pushrocks/smartstring": "^3.0.24",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
"@types/default-gateway": "^3.0.1",
|
"@types/default-gateway": "^3.0.1",
|
||||||
|
"@types/speedtest-net": "^2.1.0",
|
||||||
"isopen": "^1.3.0",
|
"isopen": "^1.3.0",
|
||||||
"public-ip": "^4.0.3",
|
"public-ip": "^4.0.3",
|
||||||
"speedtest-net": "^2.1.1",
|
"speedtest-net": "^2.1.1",
|
||||||
|
@ -9,9 +9,9 @@ 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 () => {
|
||||||
|
@ -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;
|
||||||
};
|
|
||||||
client: {
|
|
||||||
ip: string;
|
|
||||||
lat: number;
|
|
||||||
lon: number;
|
|
||||||
isp: string;
|
isp: string;
|
||||||
isprating: string;
|
interface: {
|
||||||
rating: number;
|
internalIp: string;
|
||||||
ispdlavg: number;
|
name: string;
|
||||||
ispulavg: number;
|
macAddr: string;
|
||||||
|
isVpn: false;
|
||||||
|
externalIp: string;
|
||||||
};
|
};
|
||||||
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 = await plugins.speedtestNet({ acceptGdpr: true, acceptLicense: true });
|
||||||
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
|
||||||
|
Reference in New Issue
Block a user