Merge branch 'new-ping' into staging
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 1m21s

This commit is contained in:
2025-12-30 14:52:25 +07:00
2 changed files with 1050 additions and 1717 deletions

View File

@@ -58,20 +58,6 @@ const fetchServers = async (): Promise<Server[]> => {
tcp: false, tcp: false,
}, },
}, },
{
id: "eu",
name: "Europe",
location: "Frankfurt",
subdomain: "eu.tunnl.live",
coordinates: [8.6821, 50.1109],
ping: null,
status: "online",
pingStatus: "idle",
capabilities: {
http: true,
tcp: false,
},
},
{ {
id: "sgp", id: "sgp",
name: "Singapore", name: "Singapore",
@@ -93,25 +79,7 @@ const fetchServers = async (): Promise<Server[]> => {
blockedPorts: [8080, 8443, 9000], blockedPorts: [8080, 8443, 9000],
supportsAutoAssign: true, supportsAutoAssign: true,
}, },
}, }
{
id: "id",
name: "Indonesia",
location: "Bogor",
subdomain: "id.tunnl.live",
coordinates: [106.8456, -6.595],
ping: null,
status: "online",
pingStatus: "idle",
capabilities: {
http: true,
tcp: true,
},
portRestrictions: {
blockedPorts: [22, 80, 443, 3306, 5432, 6379],
supportsAutoAssign: true,
},
},
] ]
return mockServers.filter((server) => server.status === "online") return mockServers.filter((server) => server.status === "online")
@@ -125,76 +93,58 @@ const testServerPing = (
const timeout = 5000 const timeout = 5000
let resolved = false let resolved = false
const pingUrl = `wss://ping.${server.subdomain}` const pingUrl = `https://ping.${server.subdomain}`
try { const timeoutId = setTimeout(() => {
const ws = new WebSocket(pingUrl) if (!resolved) {
resolved = true
const timeoutId = setTimeout(() => { resolve({
if (!resolved) { server,
resolved = true ping: null,
ws.close() status: "timeout",
resolve({ })
server,
ping: null,
status: "timeout",
})
}
}, timeout)
ws.onopen = () => {
console.log(`Connected to ${pingUrl}`)
} }
}, timeout)
ws.onmessage = (event) => { fetch(pingUrl, {
if (event.data === "pong" && !resolved) { method: "HEAD",
resolved = true cache: "no-cache",
const ping = Date.now() - startTime })
clearTimeout(timeoutId) .then((res) => {
ws.close() if (resolved) return
resolve({ resolved = true
server, clearTimeout(timeoutId)
ping,
status: "success",
})
}
}
ws.onclose = (event) => {
if (!resolved) {
resolved = true
clearTimeout(timeoutId)
if (!res.ok) {
resolve({ resolve({
server, server,
ping: null, ping: null,
status: "failed", status: "failed",
}) })
return
} }
}
ws.onerror = (error) => { const ping = Date.now() - startTime
if (!resolved) {
resolved = true
clearTimeout(timeoutId)
console.error(`WebSocket error for ${pingUrl}:`, error)
resolve({ resolve({
server, server,
ping: null, ping,
status: "failed", status: "success",
}) })
} })
} .catch((err) => {
} catch (error) { if (resolved) return
console.error(`Failed to create WebSocket for ${pingUrl}:`, error) resolved = true
resolve({ clearTimeout(timeoutId)
server,
ping: null, console.error(`HEAD ping error for ${pingUrl}:`, err)
status: "failed", resolve({
server,
ping: null,
status: "failed",
})
}) })
}
}) })
} }

2639
package-lock.json generated

File diff suppressed because it is too large Load Diff