fix(core): update

This commit is contained in:
Philipp Kunz 2021-04-13 10:29:42 +00:00
parent f709238e50
commit 10ef1d0455
2 changed files with 24 additions and 34 deletions

View File

@ -10,8 +10,8 @@ tap.test('should create a valid instance of SmartNetwork', async () => {
tap.test('should perform a speedtest', async () => {
const result = await testSmartNetwork.getSpeed();
console.log(`Download speed for this instance is ${result.speeds.download}`);
console.log(`Upload speed for this instance is ${result.speeds.upload}`);
console.log(`Download speed for this instance is ${result.download.bandwidth}`);
console.log(`Upload speed for this instance is ${result.download.bandwidth}`);
});
tap.test('should determine wether a port is free', async () => {

View File

@ -1,34 +1,31 @@
import * as plugins from './smartnetwork.plugins';
export interface ISpeedtestData {
speeds: {
download: number;
upload: number;
originalDownload: number;
originalUpload: number;
};
client: {
ip: string;
lat: number;
lon: number;
timestamp: Date;
ping: { jitter: number; latency: number };
download: { bandwidth: number; bytes: number; elapsed: number };
upload: { bandwidth: number; bytes: number; elapsed: number };
packetLoss: number;
isp: string;
isprating: string;
rating: number;
ispdlavg: number;
ispulavg: number;
interface: {
internalIp: string;
name: string;
macAddr: string;
isVpn: false;
externalIp: string;
};
server: {
host: string;
lat: number;
lon: number;
id: number;
name: string;
location: string;
country: string;
cc: string;
sponsor: string;
distance: number;
distanceMi: number;
ping: number;
host: string;
port: number;
ip: string;
};
result: {
id: string;
url: string;
};
}
@ -41,15 +38,8 @@ export class SmartNetwork {
* @param measurementTime
*/
public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
const done = plugins.smartpromise.defer<ISpeedtestData>();
const test = plugins.speedtestNet({ maxTime: measurementTime });
test.on('data', (data) => {
done.resolve(data);
});
test.on('error', (err) => {
done.reject(err);
});
return await done.promise;
const test = await plugins.speedtestNet({ maxTime: measurementTime, acceptGdpr: true });
return test;
}
/**