/** * Fetch WebRTC failure reason (e.g. wrong host). Pure: same inputs → same output. * @returns {Promise<{ wrongHost: { serverHostname: string, clientHostname: string } | null }>} Failure reason or null. */ export async function getWebRTCFailureReason() { try { const res = await $fetch('/api/live/debug-request-host', { credentials: 'include' }) const clientHostname = typeof window !== 'undefined' ? window.location.hostname : '' const serverHostname = res?.hostname ?? '' if (serverHostname && clientHostname && serverHostname !== clientHostname) { return { wrongHost: { serverHostname, clientHostname } } } } catch { // ignore } return { wrongHost: null } }