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 () => { tap.test('should perform a speedtest', async () => {
const 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 () => {

View File

@ -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;
}; };
} }
@ -41,15 +38,8 @@ export class SmartNetwork {
* @param measurementTime * @param measurementTime
*/ */
public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> { public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
const done = plugins.smartpromise.defer<ISpeedtestData>(); const test = await plugins.speedtestNet({ maxTime: measurementTime, acceptGdpr: 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;
} }
/** /**