diff --git a/backend/src/routes/telephony.ts b/backend/src/routes/telephony.ts index db94a30..7dc6647 100644 --- a/backend/src/routes/telephony.ts +++ b/backend/src/routes/telephony.ts @@ -11,6 +11,17 @@ const telephonyEnabled = () => const asteriskHttpStatusUrl = () => process.env.TELEPHONY_ASTERISK_HTTP_URL || "http://asterisk-dev:8088/ws" +const asteriskHttpStatusUrls = () => { + const configuredUrl = asteriskHttpStatusUrl() + return Array.from(new Set([ + configuredUrl, + "http://asterisk-dev:8088/ws", + "http://host.docker.internal:8088/ws", + `http://127.0.0.1:${process.env.TELEPHONY_DEV_WS_PORT || "8088"}/ws`, + `http://localhost:${process.env.TELEPHONY_DEV_WS_PORT || "8088"}/ws`, + ])) +} + const publicAsteriskWsUrl = () => process.env.TELEPHONY_ASTERISK_WS_URL || `ws://localhost:${process.env.TELEPHONY_DEV_WS_PORT || "8088"}/ws` @@ -54,40 +65,52 @@ export default async function telephonyRoutes(server: FastifyInstance) { server.get("/telephony/status", async () => { const enabled = telephonyEnabled() - const url = asteriskHttpStatusUrl() + const urls = asteriskHttpStatusUrls() - if (!enabled) { - return { - enabled, - provider: "asterisk", - reachable: false, - statusUrl: url, - message: "Telefonie ist nicht aktiviert.", + let lastError: any = null + const attempts = [] + + for (const url of urls) { + try { + const response = await fetchWithTimeout(url) + attempts.push({ + url, + reachable: true, + statusCode: response.status, + }) + + return { + enabled, + provider: "asterisk", + reachable: true, + statusCode: response.status, + statusUrl: url, + attempts, + message: enabled + ? (response.ok ? "Asterisk ist erreichbar." : `Asterisk-HTTP ist erreichbar (HTTP ${response.status}).`) + : "Asterisk ist erreichbar, Telefonie ist aber noch nicht aktiviert.", + } + } catch (error: any) { + lastError = error + attempts.push({ + url, + reachable: false, + message: error?.name === "AbortError" + ? "Abgelaufen" + : (error?.message || "Nicht erreichbar"), + }) } } - try { - const response = await fetchWithTimeout(url) - return { - enabled, - provider: "asterisk", - reachable: true, - statusCode: response.status, - statusUrl: url, - message: response.ok - ? "Asterisk ist erreichbar." - : `Asterisk-HTTP ist erreichbar (HTTP ${response.status}).`, - } - } catch (error: any) { - return { - enabled, - provider: "asterisk", - reachable: false, - statusUrl: url, - message: error?.name === "AbortError" - ? "Asterisk-Statusabfrage ist abgelaufen." - : (error?.message || "Asterisk ist nicht erreichbar."), - } + return { + enabled, + provider: "asterisk", + reachable: false, + statusUrl: urls[0], + attempts, + message: lastError?.name === "AbortError" + ? "Asterisk-Statusabfrage ist abgelaufen." + : (lastError?.message || "Asterisk ist nicht erreichbar."), } }) } diff --git a/frontend/pages/communication/phone.vue b/frontend/pages/communication/phone.vue index 99bdce6..1e393b5 100644 --- a/frontend/pages/communication/phone.vue +++ b/frontend/pages/communication/phone.vue @@ -11,13 +11,15 @@ const websocketResult = ref(null) const lastUpdated = ref(null) const statusColor = computed(() => { + if (status.value?.reachable) return "success" if (!status.value?.enabled) return "warning" - return status.value?.reachable ? "success" : "error" + return "error" }) const statusIcon = computed(() => { + if (status.value?.reachable) return "i-heroicons-signal" if (!status.value?.enabled) return "i-heroicons-pause-circle" - return status.value?.reachable ? "i-heroicons-signal" : "i-heroicons-signal-slash" + return "i-heroicons-signal-slash" }) const websocketColor = computed(() => { @@ -174,7 +176,7 @@ onMounted(loadTelephony) Status

- {{ status?.enabled ? (status?.reachable ? "Erreichbar" : "Nicht erreichbar") : "Deaktiviert" }} + {{ status?.reachable ? "Erreichbar" : (status?.enabled ? "Nicht erreichbar" : "Deaktiviert") }}

@@ -206,6 +208,24 @@ onMounted(loadTelephony) :title="status?.message || 'Telefonie wird geladen'" :description="status?.statusUrl || 'Noch keine Status-URL geladen.'" /> + +
+

+ Geprüfte Status-Ziele +

+
+
+ {{ attempt.url }} + + {{ attempt.reachable ? `HTTP ${attempt.statusCode}` : "offline" }} + +
+
+