Skip to content

Forward signal/close to legacy clients - #39

Open
masnwilliams wants to merge 1 commit into
masterfrom
hypeship/legacy-signal-close
Open

masnwilliams wants to merge 1 commit into
masterfrom
hypeship/legacy-signal-close

Conversation

@masnwilliams

@masnwilliams masnwilliams commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

When the server destroys a viewer's WebRTC peer while its websocket stays open (for example, ICE goes disconnected after a phone locks or backgrounds the page for longer than disconnectedTimeout), the session sends signal/close. The legacy (v2) protocol proxy has no translation for it, so it logs couldn't rewrite text message error="unknown event type: signal/close" and drops it. The legacy client never learns the stream is gone and keeps showing a black video element over an open websocket.

Changes

  • Add signal/close to the legacy event set and forward it to the client as {"event":"signal/close"}.
  • Clients that don't know the event ignore it (the v2 client logs unhandled events and continues), so nothing changes for them. The Kernel live view client uses it to reconnect.

Not included

Raising disconnectedTimeout (4s) in internal/webrtc/manager.go would let short app switches keep the same peer, but it is an upstream constant that applies to every viewer: a dead peer keeps its encoder pipelines and bandwidth for the extra seconds before it is destroyed. Left as a separate decision.

Testing

  • go test ./internal/http/legacy/ -run SignalClose: passes. The new test fails against the previous wstoclient.go with unknown event type: signal/close.
  • go vet ./internal/http/legacy/ clean.

Note

Low Risk
Narrow protocol-bridge change with a unit test; no auth or data-path changes.

Overview
Fixes a gap where the server emits signal/close after tearing down a viewer's WebRTC peer (e.g. ICE disconnected past timeout) but the legacy v2 websocket proxy treated it as unknown and dropped it, leaving clients with a black video while the socket stayed open.

Adds SIGNAL_CLOSE to the legacy event constants and a wsToClient branch that forwards it as {"event":"signal/close"}. Clients that do not handle the event are unchanged; clients that do can reconnect.

Includes TestWsToClientForwardsSignalClose to assert the legacy client websocket receives the forwarded event.

Reviewed by Cursor Bugbot for commit f82810f. Bugbot is set up for automated code reviews on this repo. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant