Files
smartping/ts/smartping.classes.smartping.ts
T

22 lines
602 B
TypeScript
Raw Permalink Normal View History

2022-10-21 11:55:42 +02:00
import * as plugins from './smartping.plugins.js';
export type TPingResponse = Awaited<ReturnType<typeof plugins.ping.promise.probe>>;
2022-10-21 11:55:42 +02:00
export class Smartping {
public async ping(hostArg: string, timeoutArg: number = 500): Promise<TPingResponse> {
2022-10-21 11:55:42 +02:00
const result = await plugins.ping.promise.probe(hostArg, {
timeout: timeoutArg
});
2022-10-21 11:55:42 +02:00
return result;
}
public async pingAlive(hostArg: string, timeoutArg: number = 500): Promise<boolean> {
try {
const result = await this.ping(hostArg, timeoutArg);
return result.alive;
} catch {
2022-10-21 11:55:42 +02:00
return false;
}
}
}