Skip to content

feat(connection): add device stream session - #2

Merged
lutz-grex merged 7 commits into
mainfrom
feat/connection
Nov 14, 2026
Merged

lutz-grex merged 7 commits into
mainfrom
feat/connection

Conversation

@lutz-grex

@lutz-grex lutz-grex commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

DeviceStreamSession connects the package to a Mobilerun cloud device the way @mobilerun/react does: WebSocket signalling plus WebRTC, session status, raw control sending, and recovery through the reconnect controller. A closed signalling socket ends the session on the server, so it is treated as a failure that rebuilds the socket and the peer connection, like a failed or closed peer connection.

Changes

  • Public surface: DeviceStreamSession(credentials:, config:) with status, videoSize, start(), retry(), close(), setMuted(), sendControl(), sendHover() (hover channel only), openUrl(), screenshot(); plus StreamCredentials, StreamCredentialsProvider, StreamConfig, StreamStatus, VideoSize and StreamSessionException. No flutter_webrtc type and no transport seam is exported; the video stream and withTransports are @internal until the video widget lands.
  • lib/src/core/: the session (API and reconnect wiring), StreamAttempt (one connect attempt: negotiation, refresh and grace window, keepAlive, frame requests, size poll), the transport interfaces, the video codec order helper (VP9, H.265, H.264, rest; H.264 plus rtx/red/ulpfec/flexfec only when there is no H.265 decoder).
  • lib/src/webrtc/: web_socket_channel signalling and flutter_webrtc peer implementations. maxRetransmits: 0 of the hover channel is passed explicitly because flutter_webrtc drops a value of 0, which would make the channel reliable. A fallback media stream (a track without stream ids) is owned and disposed with the peer.
  • When the retry budget is spent the last attempt is retired, so a late peer event cannot bring the stream back without retry(). A socket that opens while close() runs is closed.
  • Conformance fixtures synced to v0.1.1; the reconnect policy test follows the moved handshake timeouts.
  • example/: sample app (lib/main.dart, public constructor), lib/stream_view.dart (renders the stream), and a scripted emulator run (lib/e2e_main.dart, tool/e2e_android.sh, tool/png_check.py).
  • CI: both example entry points are built as debug APKs on ubuntu-latest.

Testing

  • flutter analyze, dart format --set-exit-if-changed ., flutter test are green (302 tests).
  • Tests replay signalling/sequence.json with fake transports and a virtual clock: sent frames, order and timing (request frames, keepAlive, candidate buffering), mid-session refresh with the 15 s grace window, socket close and peer failure rebuilds, token rejection (401) asking for credentials again, open and configuration timeouts, unavailable after six attempts and manual retry, the retired attempt after exhaustion, a socket opening during close(), screenshot success / error / timeout / ids, sends dropped while a channel is not open, setMuted, and close() releasing every timer.

Runtime

Android emulator (arm64, Android 16) against a dev cloud Android device, scripted run of the example:

  • First frame about 4 s after start (H.265). Every emulator screenshot of the live stream shows the device picture in the video area (about 89 % of the video rectangle lit).
  • HOME key and a tap on the Settings icon as raw control bytes through sendControl: the device screenshot changes and so do 80 % of the pixels in the video rectangle.
  • Forced signalling socket close: reconnecting(1), then connected with a new video stream; HOME and the tap work again on the rebuilt session.
  • Credential refresh replayed through a debug hook: the restart offer carries a new ICE ufrag, the server answers it, the session stays connected and 641 frames decode over the next 16 s with no reconnecting.
  • Cause of an earlier empty video area in the example: RTCVideoView reads renderVideo once per build, so the view has to be rebuilt when the renderer changes. The session was not involved.
  • Not run: iOS and a physical device.

@lutz-grex
lutz-grex merged commit 71411b0 into main Nov 14, 2026
2 checks passed
@lutz-grex
lutz-grex deleted the feat/connection branch November 14, 2026 02:57
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