UNPKG

pipebomb.js

Version:

Library for interacting with Pipe Bomb servers

37 lines 1.11 kB
import Axios from "axios"; export default class ServerInfo { constructor(address, name, https, uptime) { this.address = address; this.name = name; this.uptime = uptime; this.status = "offline"; this.status = https ? "secure" : "insecure"; } getUrl() { return `http${this.status == "secure" ? "s" : ""}://${this.address}`; } async getLatency(timeout) { const url = this.getUrl() + "/v1/identify"; let total = 0; try { for (let i = 0; i < 5; i++) { const start = Date.now(); const { data } = await Axios.get(url, { timeout: timeout || 3000 }); if (!data?.response.pipeBombServer) throw "not pipe bomb server"; total += Date.now() - start; } } catch { this.status = "offline"; return null; } return Math.round(total / 5); } getStatus() { return this.status; } } //# sourceMappingURL=ServerInfo.js.map