ext: /health check blocks recording when the backend is offline, strobing offline alarm in popup
This commit is contained in:
@@ -60,6 +60,7 @@ Base URL `http://127.0.0.1:18765`.
|
|||||||
| Method | Path | Params |
|
| Method | Path | Params |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| GET | `/status` | all recordings + pipeline status |
|
| GET | `/status` | all recordings + pipeline status |
|
||||||
|
| GET | `/health` | `ok` when the server is up (the extension checks it before recording) |
|
||||||
| GET | `/report` | `name` → report HTML |
|
| GET | `/report` | `name` → report HTML |
|
||||||
| GET | `/pdf` | `name` → report PDF |
|
| GET | `/pdf` | `name` → report PDF |
|
||||||
| GET | `/search` | `q` → full-text search over transcripts/topics |
|
| GET | `/search` | `q` → full-text search over transcripts/topics |
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "Teams Whisper Recorder",
|
"name": "Teams Whisper Recorder",
|
||||||
"version": "1.1",
|
"version": "1.2",
|
||||||
"description": "Record Teams tab audio+video (+mic) and transcribe with local whisper server",
|
"description": "Record Teams tab audio+video (+mic) and transcribe with local whisper server",
|
||||||
"permissions": ["tabCapture", "offscreen", "activeTab", "tabs", "declarativeNetRequest"],
|
"permissions": ["tabCapture", "offscreen", "activeTab", "tabs", "declarativeNetRequest"],
|
||||||
"host_permissions": ["http://127.0.0.1:18765/*", "https://teams.cloud.microsoft/*", "https://teams.microsoft.com/*"],
|
"host_permissions": ["http://127.0.0.1:18765/*", "https://teams.cloud.microsoft/*", "https://teams.microsoft.com/*"],
|
||||||
|
|||||||
@@ -7,6 +7,18 @@
|
|||||||
body[data-state=transcribing] { --accent: #2563eb; }
|
body[data-state=transcribing] { --accent: #2563eb; }
|
||||||
body[data-state=done] { --accent: #16a34a; }
|
body[data-state=done] { --accent: #16a34a; }
|
||||||
body[data-state=error] { --accent: #d97706; }
|
body[data-state=error] { --accent: #d97706; }
|
||||||
|
body[data-state=offline] { --accent: #dc2626; }
|
||||||
|
#off { margin-bottom: 12px; padding: 12px 14px; border-radius: 8px; background: #fef2f2; border: 2px solid #dc2626; color: #7f1d1d; }
|
||||||
|
#off b { display: block; margin-bottom: 4px; font-size: 15px; color: #b91c1c; }
|
||||||
|
#off ol { margin: 8px 0 0; padding-left: 20px; }
|
||||||
|
body[data-state=offline] #st, body[data-state=offline] #txt { display: none; }
|
||||||
|
body[data-state=offline] #go:disabled { opacity: 1; background: #fecaca; color: #991b1b; }
|
||||||
|
/* Offline alarm: banner, button and dot strobe red/white. 0.4 s per cycle = 2.5 flashes/s, under the 3/s photosensitivity limit.
|
||||||
|
No prefers-reduced-motion opt-out on purpose: Windows with animations off reports "reduce" and would hide the alarm. */
|
||||||
|
body[data-state=offline] #off { animation: strobe .4s steps(1) infinite; }
|
||||||
|
body[data-state=offline] #go:disabled, body[data-state=offline] .dot { animation: strobe .4s steps(1) infinite reverse; }
|
||||||
|
@keyframes strobe { 0% { background: #dc2626; color: #fff; border-color: #fff; } 50% { background: #fff; color: #b91c1c; border-color: #dc2626; } }
|
||||||
|
body[data-state=offline] #off b { color: inherit; }
|
||||||
h1 { margin: 0 0 12px; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
|
h1 { margin: 0 0 12px; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
|
||||||
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
|
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
|
||||||
body[data-state=recording] .dot { animation: pulse 1.2s infinite; }
|
body[data-state=recording] .dot { animation: pulse 1.2s infinite; }
|
||||||
@@ -18,14 +30,27 @@
|
|||||||
#st { margin-top: 12px; padding: 8px 10px; background: #fff; border: 1px solid #e2e8f0; border-left: 3px solid var(--accent); border-radius: 6px; word-break: break-word; }
|
#st { margin-top: 12px; padding: 8px 10px; background: #fff; border: 1px solid #e2e8f0; border-left: 3px solid var(--accent); border-radius: 6px; word-break: break-word; }
|
||||||
#txt { margin: 12px 0 0; padding: 10px; white-space: pre-wrap; max-height: 260px; overflow: auto; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px; font: 12px/1.45 ui-monospace, Consolas, monospace; }
|
#txt { margin: 12px 0 0; padding: 10px; white-space: pre-wrap; max-height: 260px; overflow: auto; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px; font: 12px/1.45 ui-monospace, Consolas, monospace; }
|
||||||
#txt:empty { display: none; }
|
#txt:empty { display: none; }
|
||||||
|
#srv { margin-top: 8px; font-size: 12px; color: #475569; display: flex; align-items: center; gap: 6px; }
|
||||||
|
#srv::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
|
||||||
|
#srv[data-ok=true]::before { background: #16a34a; }
|
||||||
|
#srv[data-ok=false] { color: #dc2626; font-weight: 600; }
|
||||||
|
#srv[data-ok=false]::before { background: #dc2626; }
|
||||||
a { display: inline-block; margin-top: 12px; color: #475569; font-size: 12px; }
|
a { display: inline-block; margin-top: 12px; color: #475569; font-size: 12px; }
|
||||||
</style>
|
</style>
|
||||||
<body data-state="idle">
|
<body data-state="idle">
|
||||||
<h1><span class="dot"></span>Teams Whisper</h1>
|
<h1><span class="dot"></span>Teams Whisper</h1>
|
||||||
|
<!-- Shown by popup.js when /health fails and nothing is recording. -->
|
||||||
|
<div id="off" hidden>
|
||||||
|
<b>Backend offline. Recording is NOT possible.</b>
|
||||||
|
The Teams Whisper server (127.0.0.1:18765) is not running, so nothing would be saved.
|
||||||
|
<ol><li>Open Pinokio, then Teams Whisper, then press <b style="display:inline;font-size:inherit">Start</b>.</li><li>Wait until the dot below turns green.</li><li>Press Start here again.</li></ol>
|
||||||
|
</div>
|
||||||
<!-- Start/Stop; popup.js drives it. -->
|
<!-- Start/Stop; popup.js drives it. -->
|
||||||
<button id="go">Start</button>
|
<button id="go">Start</button>
|
||||||
<!-- Status line, filled by popup.js. -->
|
<!-- Status line, filled by popup.js. -->
|
||||||
<div id="st"></div>
|
<div id="st"></div>
|
||||||
|
<!-- Backend health (/health), refreshed every second by popup.js. -->
|
||||||
|
<div id="srv"></div>
|
||||||
<!-- Transcript/result text returned by the recorder. -->
|
<!-- Transcript/result text returned by the recorder. -->
|
||||||
<pre id="txt"></pre>
|
<pre id="txt"></pre>
|
||||||
<!-- mic.html opens in a new tab so the permission prompt can appear; needed once. -->
|
<!-- mic.html opens in a new tab so the permission prompt can appear; needed once. -->
|
||||||
|
|||||||
+17
-6
@@ -6,16 +6,24 @@ const sendToOffscreen = message => chrome.runtime.sendMessage({ to: "off", ...me
|
|||||||
// Format milliseconds as m:ss.
|
// Format milliseconds as m:ss.
|
||||||
const formatElapsed = milliseconds => { const totalSeconds = Math.floor(milliseconds / 1000); return `${Math.floor(totalSeconds / 60)}:${String(totalSeconds % 60).padStart(2, "0")}`; };
|
const formatElapsed = milliseconds => { const totalSeconds = Math.floor(milliseconds / 1000); return `${Math.floor(totalSeconds / 60)}:${String(totalSeconds % 60).padStart(2, "0")}`; };
|
||||||
// Last error shown when there is no offscreen document to report it.
|
// Last error shown when there is no offscreen document to report it.
|
||||||
let recorderState = { state: "idle" }, lastError = "";
|
let recorderState = { state: "idle" }, lastError = "", serverOk = null;
|
||||||
|
// Backend liveness (server.py /health); false on any error or after 1.5 s.
|
||||||
|
const serverUp = () => fetch("http://127.0.0.1:18765/health", { signal: AbortSignal.timeout(1500) }).then(response => response.ok, () => false);
|
||||||
|
|
||||||
// Refresh the button and status line from state recorderState.
|
// Refresh the button and status line from state recorderState.
|
||||||
function render() {
|
function render() {
|
||||||
const goButton = byId("go"), statusLine = byId("st");
|
const goButton = byId("go"), statusLine = byId("st");
|
||||||
document.body.dataset.state = recorderState.state;
|
// Backend down and not mid-recording: starting is impossible, the offline banner replaces the status line.
|
||||||
|
const offline = serverOk === false && recorderState.state !== "recording";
|
||||||
|
document.body.dataset.state = offline ? "offline" : recorderState.state;
|
||||||
|
byId("off").hidden = !offline;
|
||||||
// Pipeline busy after stop: no new start until it finishes.
|
// Pipeline busy after stop: no new start until it finishes.
|
||||||
goButton.disabled = recorderState.state === "transcribing";
|
goButton.disabled = offline || recorderState.state === "transcribing";
|
||||||
|
// Backend indicator under the button.
|
||||||
|
byId("srv").dataset.ok = serverOk ?? "";
|
||||||
|
byId("srv").textContent = serverOk == null ? "server: checking..." : serverOk ? "server: online" : "server: OFFLINE";
|
||||||
// Button doubles as Stop while recording.
|
// Button doubles as Stop while recording.
|
||||||
goButton.textContent = recorderState.state === "recording" ? "Stop + transcribe" : "Start";
|
goButton.textContent = offline ? "Recording blocked: server offline" : recorderState.state === "recording" ? "Stop + transcribe" : "Start";
|
||||||
// Status line text per recorder state.
|
// Status line text per recorder state.
|
||||||
statusLine.textContent = {
|
statusLine.textContent = {
|
||||||
idle: "idle - open a Teams tab and press Start",
|
idle: "idle - open a Teams tab and press Start",
|
||||||
@@ -30,8 +38,9 @@ function render() {
|
|||||||
|
|
||||||
// Poll the recorder state every second.
|
// Poll the recorder state every second.
|
||||||
async function poll() {
|
async function poll() {
|
||||||
// Offscreen doc exists: ask it for its state. Otherwise show the last error, or idle.
|
// A failed Start wins; else ask the offscreen doc (if any) for its state, or show idle.
|
||||||
if (await chrome.offscreen.hasDocument()) recorderState = (await sendToOffscreen({ cmd: "status" })) || recorderState; else recorderState = lastError ? { state: "error", text: lastError } : { state: "idle" };
|
recorderState = lastError ? { state: "error", text: lastError } : (await chrome.offscreen.hasDocument()) ? (await sendToOffscreen({ cmd: "status" })) || recorderState : { state: "idle" };
|
||||||
|
serverOk = await serverUp();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +63,8 @@ byId("go").onclick = async () => {
|
|||||||
if (activeTab.url?.startsWith("chrome-extension:")) throw new Error("This is the extension's own page. Switch to the Teams tab, then click the icon.");
|
if (activeTab.url?.startsWith("chrome-extension:")) throw new Error("This is the extension's own page. Switch to the Teams tab, then click the icon.");
|
||||||
// Stream id that the offscreen document later passes to getUserMedia.
|
// Stream id that the offscreen document later passes to getUserMedia.
|
||||||
const streamId = await chrome.tabCapture.getMediaStreamId({ targetTabId: activeTab.id });
|
const streamId = await chrome.tabCapture.getMediaStreamId({ targetTabId: activeTab.id });
|
||||||
|
// Health check before recording: backend down = nothing would be saved, so show the offline banner and stop here.
|
||||||
|
if (!(serverOk = await serverUp())) return render();
|
||||||
// Create the offscreen document once; it stays alive while recording.
|
// Create the offscreen document once; it stays alive while recording.
|
||||||
if (!(await chrome.offscreen.hasDocument()))
|
if (!(await chrome.offscreen.hasDocument()))
|
||||||
await chrome.offscreen.createDocument({ url: "offscreen.html", reasons: ["USER_MEDIA"], justification: "record tab" });
|
await chrome.offscreen.createDocument({ url: "offscreen.html", reasons: ["USER_MEDIA"], justification: "record tab" });
|
||||||
|
|||||||
@@ -859,6 +859,9 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
)
|
)
|
||||||
elif parsed.path == "/status":
|
elif parsed.path == "/status":
|
||||||
self._json(status())
|
self._json(status())
|
||||||
|
# Cheap liveness probe for the extension (checked before recording starts).
|
||||||
|
elif parsed.path == "/health":
|
||||||
|
self._send(b"ok")
|
||||||
elif parsed.path == "/report":
|
elif parsed.path == "/report":
|
||||||
file_path = out_root / name / "report.html"
|
file_path = out_root / name / "report.html"
|
||||||
self._send(
|
self._send(
|
||||||
|
|||||||
Reference in New Issue
Block a user