fix(package): modernize package configuration and stabilize ping typings and tests
This commit is contained in:
@@ -1,22 +1,21 @@
|
||||
import * as plugins from './smartping.plugins.js';
|
||||
|
||||
export type TPingResponse = Awaited<ReturnType<typeof plugins.ping.promise.probe>>;
|
||||
|
||||
export class Smartping {
|
||||
public async ping(hostArg: string, timeoutArg: number = 500): Promise<plugins.ping.PingResponse> {
|
||||
public async ping(hostArg: string, timeoutArg: number = 500): Promise<TPingResponse> {
|
||||
const result = await plugins.ping.promise.probe(hostArg, {
|
||||
timeout: timeoutArg
|
||||
})
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public async pingAlive(hostArg: string, timeoutArg: number = 500): Promise<boolean> {
|
||||
const result = await plugins.ping.promise.probe(hostArg, {
|
||||
timeout: timeoutArg
|
||||
}).catch();
|
||||
//console.log(result);
|
||||
if (result.alive) {
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
const result = await this.ping(hostArg, timeoutArg);
|
||||
return result.alive;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user