sh2/d2ypp2/services/neko/live-ops-extension/background.js
eric 9888f1daad Harden YouTube unmanned live stack and hide advanced console panels.
Fix Pro config SSOT, event FSM, FFmpeg error tiers, relay heartbeat, and ingest auth while keeping relay snapshot, quality guard, and event hub hidden in the UI.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 06:31:31 -05:00

49 lines
1.6 KiB
JavaScript

const API_BASES = [
"http://host.docker.internal:8001",
"http://127.0.0.1:8001",
"http://localhost:8001",
"http://10.0.0.237:8001",
];
async function postTelemetry(payload) {
const stored = await chrome.storage.local.get(["liveHubIngestToken"]);
const ingestToken = (stored.liveHubIngestToken || "").trim();
const body = JSON.stringify({
...payload,
source: payload.source || "chrome_extension",
received_at: Date.now() / 1000,
...(ingestToken ? { ingest_token: ingestToken } : {}),
});
let lastError = "";
for (const base of API_BASES) {
try {
const res = await fetch(`${base}/hub/youtube/live/ingest`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body,
cache: "no-store",
});
if (res.ok) {
const data = await res.json().catch(() => ({}));
await chrome.storage.local.set({
liveHubLastOk: Date.now(),
liveHubLastBase: base,
liveHubLastEvent: data?.event?.id || null,
});
return { ok: true, base, eventId: data?.event?.id || null };
}
lastError = `${base} HTTP ${res.status}`;
} catch (err) {
lastError = `${base} ${err?.message || String(err)}`;
}
}
await chrome.storage.local.set({ liveHubLastError: lastError, liveHubLastErrorAt: Date.now() });
return { ok: false, error: lastError };
}
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (!message || message.type !== "live-hub-youtube-telemetry") return false;
postTelemetry(message.payload || {}).then(sendResponse);
return true;
});