Repository navigation
Reconnect the live view after a dropped connection - #524
Open
masnwilliams wants to merge 6 commits into
Open
masnwilliams wants to merge 6 commits into
masnwilliams wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2ced795. Configure here.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
On a phone, the live view goes black when the page is locked or backgrounded and never comes back. Two things happen while the page is suspended, and the client recovered from neither:
1006). The client treated any close after connecting as final: a red "websocket closed" notification and "Browser has been shut down and is no longer available", with the browser still running.signal/close. The legacy protocol proxy dropped that message (fixed in Forward signal/close to legacy clients neko#39), and on its own the client keeps an open socket and shows a black video element with no message.On iOS Safari in Low Power Mode the first autoplay can also be refused even muted, which left a black box with no hint that a tap starts it.
This makes the live view restore a dropped session on its own, show what it is doing, and prompt for a tap only when the browser refuses playback of a live stream. It absorbs #521.
Changes
Reconnect (
utils/reconnect.ts,neko/base.ts,neko/index.ts)4410);signal/closefrom the server;failed/closed, ordisconnectedwith the socket already gone;visibilitychange(visible),pageshowandonlineretry at once.getStats). iOS can resume a page with a socket that reads as open and a peer the server already destroyed, and nothing fires. On desktop, where a background tab keeps streaming, this check passes and nothing reconnects.4410(the proxy's session-gone code) ends it.system/disconnectends it, as before (kicked, ...), exceptconnection shutdown. neko sends that as it stops on a restart as well as on teardown, so the socket close that follows decides.disconnect()clears buffered remote ICE candidates, so candidates from a dropped attempt can't reach the next peer.KERNEL_CONNECTION_TIMEOUT/KERNEL_CONNECTION_FAILED, no retry. A failed reconnect attempt posts neither and doesn't give up.UI and parent frame
connection.reconnectingstring). The red notification only shows when the session has ended. "Browser has been shut down" only shows for a real end state.KERNEL_*style:KERNEL_RECONNECTINGwithattempt, for each pending attempt;KERNEL_DISCONNECTEDwithreason, once an established session ends;KERNEL_CONNECTEDis posted again after a successful reconnect, as on first connect.Autoplay (from #521,
components/video.vue)NotAllowedErroron a touch device shows "Tap to start live view" (aria-label matches). The text reads "Click to start live view" when the pointer isn't coarse (matchMedia('(pointer: coarse)'), falling back to touch support); the prompt itself still only appears on touch devices.play()runs again, and the prompt returns only if that is refused too.Testing
bun test tests: 299 pass. New tests:signal/closecloses the socket and drops; failed and timed-out reconnect attempts are retried; candidates from a dropped attempt are cleared; without reporting or giving up; a successful reconnect reports connected again;4410and server disconnects end the session; a first connect that never succeeded is not recoverable;matchMedia, and the aria-label matching the text.All but the successful-reconnect test fail against the previous client.
npm run buildpasses with the same lint warnings asmain. Prettier is clean.Production browsers. Two fresh headful stealth browsers at 390x844. One got this branch's client hot-patched in (built from the deployed client source plus only this diff; the unpatched rebuild matches the deployed bundle byte for byte), plus a neko binary built from
v3.0.8-v1.6.4with only Forward signal/close to legacy clients neko#39 applied. The other stayed as shipped. Viewer: headless Chromium on desktop, sampling once a second whether the socket was open, whether RTP bytes were arriving, and the overlay text.signal/closearrives, "Reconnecting...", new socket and peer, media back ~5s after the drop with UDP still blockedsupervisorctl restart neko(connection shutdown, then close)On both, desktop load plays with sound and shows no prompt. The neko log on the patched browser shows the peer destroyed and no
couldn't rewrite text message ... signal/closeerror, followed by the client's new session. Not covered: a real iPhone (in progress), a deleted browser end to end (the probe's 401/410 handling is unit tested), Firefox.Overlaps #488 (draft), which shows a reload message instead of reconnecting.
Note
High Risk
Changes WebRTC/WebSocket lifecycle, retry policy, and parent-frame KERNEL_* messaging for the live view client—core session connectivity paths with broad mobile/desktop impact.
Overview
Automatically restores a live view after transient drops (websocket close,
signal/close, dead media on wake) instead of treating them as fatal shutdowns. A newReconnectorbacks off retries, probes the live-view URL before each attempt to stop when the session is truly over (401/403/404/410, WS4410, server kick), and retries immediately when the page becomes visible or the network returns.Connection client changes distinguish first-connect failures from recoverable drops:
recoverable,streamAlive()via RTP stats, clearing stale ICE candidates, handlingsignal/close, and only emittingKERNEL_CONNECTION_*on initial connect—not on failed reconnect tries. Embedders getKERNEL_RECONNECTING(with attempt) andKERNEL_DISCONNECTEDwhen a session really ends.UI: a semi-transparent "Reconnecting…" overlay keeps the last frame visible; the disconnected overlay only shows after a real end. On touch devices, autoplay blocked by
NotAllowedErrorshows a Tap/Click to start live view prompt (connected sessions only, cleared on drop).Tests cover the reconnect scheduler, dropped-session client behavior, stream liveness, and autoplay prompting.
Reviewed by Cursor Bugbot for commit ad0b828. Bugbot is set up for automated code reviews on this repo. Configure here.