(deps: BridgeDeps)
| 73 | } |
| 74 | |
| 75 | export function installRuntimeControlBridge(deps: BridgeDeps): (event: MessageEvent) => void { |
| 76 | const handler = (event: MessageEvent) => { |
| 77 | const data = event.data as BridgeControlData | null; |
| 78 | if (!data || data.source !== "hf-parent" || data.type !== "control") return; |
| 79 | const action = data.action; |
| 80 | if (typeof action !== "string") return; |
| 81 | const fn = CONTROL_HANDLERS[action]; |
| 82 | if (fn) fn(data, deps); |
| 83 | }; |
| 84 | window.addEventListener("message", handler); |
| 85 | // Announce that the bridge listener is installed so the parent can replay |
| 86 | // any control messages it posted before the iframe runtime was ready |
| 87 | // (avoids losing the initial `set-muted` / `set-volume` / `set-playback-rate` |
| 88 | // when the parent finishes loading before the iframe does — a deterministic |
| 89 | // race on warm-cache reloads and inside the Claude desktop Electron client). |
| 90 | postRuntimeMessage({ source: "hf-preview", type: "ready" }); |
| 91 | return handler; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Flash elements — briefly highlight them with a blue outline. |
no test coverage detected