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