Skip to content

feat(stream): nav row and resume - #9

Merged
Cyro292 merged 7 commits into
mainfrom
feat/react-stream-nav-resume
Dec 3, 2026
Merged

Cyro292 merged 7 commits into
mainfrom
feat/react-stream-nav-resume

Conversation

@lutz-grex

@lutz-grex lutz-grex commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

DeviceStream now ships the phone controls that Mobilerun Cloud shows: a dark Back / Home / Recent apps row inside the screen, and a stopped-device view with a Play button that resumes the device. Both parts are on by default and can be turned off per component.

Changes

  • Navigation row: DeviceStream renders NavigationBar under the video, inside the screen. Keys send BACK / HOME / RECENT and are disabled while the stream is not connected or hasControl is false. hideNavigation turns the row off. NavigationBar keeps its props and gains optional disabled and labels; its look changes to the dark Cloud row.
  • Stopped devices: new props deviceState and onResume. With deviceState="stopped" the stream is not opened; the screen shows a "Device stopped" pill with a power icon and a round Play button. A tap calls onResume and shows "Starting" until the state leaves stopped; if onResume rejects, the button comes back. hideResumeButton keeps the pill and hides the button. Reconnecting is paused while the device is stopped and starts fresh when it runs again.
  • useDeviceStream({ device }) returns resume() when the SDK device object supports it (@mobilerun/sdk 6.2+). It resumes, then refetches the device, also when the readiness wait fails after the resume request.
  • Labels: new optional keys back, home, recentApps, resume, stopped, starting. Existing complete label objects still type-check.
  • StreamStatusPill gains an optional icon (spinner by default, or power).
  • Example app: uses the built-in row and resumes stopped devices through two new server routes, POST /api/v1/devices/:id/resume and the read-only GET /api/v1/devices/:id/wait, with the same same-origin, id and missing-key guards as the stream-key route. The API key stays on the server.
  • README, docs/default-ui.md and the device-stream skill document the new props, flags and labels.

Upgrade notes: no version, peer range or export changes. The navigation row now appears by default and takes space inside the component's height; apps that already render their own row should remove it or set hideNavigation. The navigation buttons are type="button", so a DeviceStream inside a form never submits it.

Testing

  • bun run typecheck: pass
  • bun test: pass (0 failures)
  • bun run build: pass; the new utility classes are present in dist/styles.css
  • New tests cover key mapping and disabled state of the row, hideNavigation, the stopped view (pill, Play, Starting, rejection, state change), hideResumeButton, reconnect paused while stopped, resume() refetch after a failed readiness wait, the old label shape, and the example's resume and wait routes (happy path, invalid id, foreign origin, missing key, upstream errors).

Runtime

UNVERIFIED — no resume against a real device yet; needs one stopped dev device resumed through the example app after merge.

Release Checklist

  • Tests/CI green — CI green on 79cddf4
  • Code review by a second engineer — exception: admin merge without required approval
  • Security impact checked (auth, secrets, customer data, new dependencies) — no auth, token or secret logic in the package; no new or bumped dependencies; the example server's two new routes run behind its existing same-origin and id guards and keep the API key server-side
  • No open high/medium findings (Dependabot/scanners) — 0 open critical/high/medium Dependabot alerts; code scanning not enabled
  • Rollback plan clear (for infra/DB changes) — revert this PR; no infra, migration or published version involved
  • Docs/runbooks updated where needed — README, docs/default-ui.md and the device-stream skill updated in this PR

🤖 Generated with Claude Code

lutz-grex and others added 4 commits December 2, 2026 13:42
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@lutz-grex
lutz-grex requested a review from sleynsol December 2, 2026 14:17

@Cyro292 Cyro292 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against what the mobilerun-mcp device viewer needs, so it can use DeviceStream as is.

Works: built-in Back / Home / Recent row with the right keys, labels for the button names, hideNavigation, and the connection pill only showing while disconnected. Tests pass locally (658 pass, 28 skip, 0 fail) and so does typecheck.

High: the nav row isn't attached to the phone. See the inline comment on device-stream.tsx. Measured with this build (synthetic 360x800 video): row 800px vs phone 238px at 800x600, 1400 vs 283 at 1400x700, 320 vs 131 at 320x364. On wide screens Back / Home / Recent spread across the whole width.

High: a stale resume action can wake the wrong device. use-device-stream.ts:135-146: the callback identity changes per target, but even an old callback reads the latest handleRef.current. A caller that keeps phone A's action across a device switch resumes phone B. Bind the call to the handle it was created for, or reject stale actions.

Medium: the keys can be enabled while clicks are dropped. device-stream.tsx:238-240 checks the peer connection and hasControl, not the control data channel. remote-control.tsx:298-305 drops the key if the channel isn't open.

Medium: "Starting" can get stuck. device-stopped.tsx:31-40 clears the pending state only on rejection. If the confirming refresh after a successful resume fails, or polling is off, the state stays stopped with no Play button and no retry.

Medium: stopping doesn't report a disconnect. device-stream.tsx:211-222 clears local state but never calls onConnectionStateChange(false). External controls driven by that callback stay enabled.

Tests: nothing covers fitted row geometry, a stop then resume with a reconnect, or a connected peer with a closed control channel. device-stream-reconnect.test.tsx:23-42 renders static states only.

Nit: navigation-bar.tsx:10-13 duplicates the SystemButton type from remote-control.tsx:104-110.

Comment thread src/components/device-stream.tsx Outdated
className,
)}
>
<div className="relative flex min-h-0 w-full flex-1 items-center justify-center">{renderScreen()}</div>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: the nav row takes the container's width, not the phone's. The row is a full-width sibling under the flex-1 screen area. The video is letterboxed inside that area (styles.css:120-126, object-fit: contain), so the row never learns the phone's width. At 800x600 the row is 800px wide and the phone 238px. When the video is shorter than the screen area, a gap also opens between the phone and the row.

Suggested fix: wrap the video and the row in one centered box sized to the fitted phone picture, reserve the 36px row height before fitting the video, and keep the row non-shrinking. Please add a test for the fitted geometry.

@Cyro292 Cyro292 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for the findings in #9 (review). Blocking: the nav row must fit the phone, not the container, and a stale resume action must not wake the wrong device.

lutz-grex and others added 2 commits December 3, 2026 17:39
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cyro292
Cyro292 previously approved these changes Dec 3, 2026

@Cyro292 Cyro292 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Cyro292

Cyro292 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

@lutz-grex

package.json is still 0.4.0 (same as the latest release, v0.4.0), and this PR doesn't change it.

To ship:

  1. Bump package.json to 0.5.0 (it's a feat), in this PR or a follow-up.
  2. Merge to main.
  3. Publish a release with a matching tag, e.g. gh release create v0.5.0 --target main --generate-notes. That runs typecheck, build and npm publish for @mobilerun/react@0.5.0.

If the tag doesn't match package.json, the publish job fails. To test first, run the "Publish to npm" workflow manually with dry-run: true.

@Cyro292 Cyro292 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving after the 0.5.0 version bump (d1cad5e); only package.json version changed.

@Cyro292
Cyro292 merged commit 23ae5c1 into main Dec 3, 2026
1 check passed
@lutz-grex

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All points are fixed in 98634ea and b073a80:

  • The nav row now sits in one box with the video, sized to the fitted picture with container query units and the video's own aspect ratio. Measured in Chromium with a 360x800 source, the row is as wide as the picture with no gap at 800x600, 1400x700 and 320x364; a 1600x900 source fits too.
  • A resume callback created for one device rejects after a switch to another device and calls neither resume nor a refetch.
  • The keys are enabled only while the control data channel is open. RemoteControl reports it through a new optional onControlChannelChange.
  • "Starting" clears when onResume settles. useDeviceStream's resume resolves after its own confirming fetch, so there is no Play flash, and it doesn't hang on unmount or a device switch.
  • Stopping a connected stream calls onConnectionStateChange(false) once.
  • NavigationBar reuses SystemButton.

Each point has a test. With this, the viewer in mobilerun-mcp#61 can use the built-in row and drop its own sizing code.

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.

2 participants