Skip to content

feat(mobile): play video attachments - #659

Merged
nixuuu merged 1 commit into
devfrom
feat/mobile-video-player
Nov 14, 2026
Merged

nixuuu merged 1 commit into
devfrom
feat/mobile-video-player

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Video attachments now play inside the mobile viewer with expo-video (~58.0.14): poster, play/pause, native seeking and fullscreen controls. Playback requires a tap, starts muted, and pauses when the viewer closes, its route loses focus, or the app backgrounds. The viewer keeps the existing reduced-motion behavior. Share/Save remains available. Composer tiles adopt the gateway's detected kind after upload, including videos renamed with a non-video extension.

Authenticated streaming retains the existing pinned, routed gateway client. AVPlayer/ExoPlayer cannot use Canopy's self-signed certificate pin directly, so a small local Expo module serves bounded reads over an ephemeral loopback listener. It binds only 127.0.0.1, uses an unguessable path, expires with the viewer or after 15 idle minutes, permits four connections, and never receives device credentials or a remote gateway URL. Active reads renew the idle deadline so long videos remain seekable. Every metadata/chunk RPC remains owner-scoped, including linked computers; 256 KiB writes provide backpressure and cancellation. Production Android permits cleartext only for loopback; the existing development HTTP opt-in is preserved. No signed remote URLs, TLS bypass or model transcoding.

Native runtime change: runtimeVersion: { policy: "fingerprint" } remains in effect. Production profile fingerprints change:

Platform Before After
iOS 6ddec9ef559ee0095ac33e94ff9418a942053b17 f05d9756d267ff22288f59b90575c27b0038c9ab
Android 5f6eae3ab278f1cd543e9ed763f923a319b65ec9 c0977af96d22d12c9c7d16dc8055d4c4ffdca1cc

A new native build is required for expo-video and the media bridge. No EAS builds or OTA publication were run. Native compilation and device playback are unverified; the device check is pending because of the reported MacStudio device-host error. The maintainer handles native builds.

Validation: frozen-lockfile install, generation check, full monorepo typecheck, lint, formatting, web production build, and iOS/Android exports pass on the rebased head. Current-head CI passes all four test shards, static checks and builds. Focused gateway tests pass (7 tests, 98 assertions), including native-read ranges, multi-chunk streaming, invalid ranges, owner denial, cancellation, and disguised HTML. The attachment and domain checks also pass through check:tmp (17 tests, 143 assertions, no temporary files left). Expo autolinking resolves the local module on both platforms. Android prebuild verifies production loopback-only HTTP and the existing dev opt-in. The local config plugin is explicitly present in fingerprint inputs. No UI tests added.

Local suite results: the final four shards executed all 518 test files exactly once, with 2,766 passing tests, 166 skips and 7 failures in configuration-sync recovery and mirror recovery. Both complete files then passed (19 tests, 147 assertions). An earlier full local run also hit linked-computer moves/relay, diagnostics and GitHub PR deduplication; all four complete files passed on rerun (48 tests, 860 assertions). Every full shard and complete-file rerun left no owned temporary files. These local failures are disclosed separately from the green current-head CI gate.

Copy audit (§8): “Play on a computer” → “Play video” because playback is now available on the device. New “Loading video…” describes ongoing work; playback failure → “Could not play this video. Retry or save the file to open it in another app.” gives a concrete recovery action. Verb-led actions, sentence case, no new glossary terms, no decorative copy or duplicated status. Shared viewer/chip filenames checked at desktop and phone widths; native device text/layout check remains pending.

Stack #660: this PR depends on #658. Merge the stack together.

@nixuuu
nixuuu added this pull request to stack #660 November 13, 2026 17:42
@nixuuu
nixuuu force-pushed the feat/mobile-video-player branch 2 times, most recently from 3cda094 to 059cd71 Compare November 13, 2026 17:47
@nixuuu
nixuuu force-pushed the feat/mobile-video-player branch 5 times, most recently from 65409f1 to 248bfa4 Compare November 13, 2026 18:53
@nixuuu
nixuuu marked this pull request as ready for review November 13, 2026 19:25
@nixuuu
nixuuu marked this pull request as draft November 13, 2026 19:33
Base automatically changed from feat/preview-play-videos to dev November 13, 2026 19:34
nixuuu added a commit that referenced this pull request Nov 13, 2026
Videos attached to threads now open in the shared media viewer instead
of downloading as generic files. MP4/MOV and WebM are identified from
container bytes, show a video icon and known duration, and retain their
original bytes for workers.

The BFF serves owner-scoped HTTP byte ranges from bounded PostgreSQL
reads (256 KiB per RPC), including linked-computer attachments,
206/Content-Range, 416, HEAD and If-Range. The shared web/desktop
lightbox has native video controls, download, Space/arrow shortcuts and
pause on close, hidden tab or offscreen. Playback starts muted and
requires a user action. Mobile gets a raster poster, duration and
Share/Save with “Play on a computer”; native playback follows in the
next stack layer.

Decisions: retain the existing 20 MiB default / 30 MiB ceiling because
uploads and worker delivery still buffer originals. Use a neutral WebP
through existing sharp rather than adding a native video decoder. Keep
playback in the viewer so the timeline does not retain decoders.
Existing stored MP4/MOV MIME metadata also enables playback; legacy
homes require a whole-file fallback within the upload cap.

Validation: focused gateway/BFF integration passes (sniffing including
disguised HTML/SVG, ownership, limits, ranges and linked-home routing,
worker delivery); frozen-lockfile install, full monorepo typecheck,
lint, formatting, generation check and web production build pass on the
rebased head. Current-head CI passes all four test shards, static checks
and builds. The ask_user cancellation test failed on the first CI
attempt and passed on the failed-job retry; it also passed in the local
sharded run.

Local suite results: the final four shards executed all 518 test files
exactly once, with 2,766 passing tests, 166 skips and 7 failures in
configuration-sync recovery and mirror recovery. Both complete files
then passed (19 tests, 147 assertions). An earlier full local run also
hit linked-computer moves/relay, diagnostics and GitHub PR
deduplication; all four complete files passed on rerun (48 tests, 860
assertions). Every full shard and complete-file rerun left no owned
temporary files. These local failures are disclosed separately from the
green current-head CI gate.

Browser review on an isolated remote production stack passed in
light/dark, desktop/phone widths, with 2-second and 2-minute clips, long
filenames, hover poster, muted playback, seeking to 90 seconds, keyboard
handlers, download availability, and pause/removal on close. A browser
Range request returned 206 and the exact requested bytes. Real
linked-computer browser review was unavailable in the isolated fixture;
linked routing is integration-tested. No UI tests added. Mobile device
check pending: reported MacStudio device host error. No native
dependencies changed in this layer.

Expo fingerprints unchanged: iOS
`6ddec9ef559ee0095ac33e94ff9418a942053b17`; Android
`5f6eae3ab278f1cd543e9ed763f923a319b65ec9`.

Copy audit (§8): generic file actions → “Play video”, “Share video” /
“Save video”, and “Play on a computer” describe the available action;
playback failure → “Could not play this video. Download it to open it in
another app.” states the problem and next action. Sentence case,
verb-led actions, existing glossary, no new terms or decorative copy.
Short and long filename truncation/wrapping checked at desktop and phone
widths in light/dark.

Stack #660: native mobile playback follows in #659. Merge the stack
together.
@nixuuu
nixuuu force-pushed the feat/mobile-video-player branch from 248bfa4 to e183387 Compare November 13, 2026 19:34
nixuuu added a commit that referenced this pull request Nov 14, 2026
…688)

Mobile fallback for visuals, with no native code (docs/mobile.md
"Visuals agenta").

- `VisualSummary` shows the visual's title, "Version N" and "Open this
visual on web or desktop.", styled like the other timeline cards
(surface, ring, 12 px radius, medium title, muted meta). The description
goes into the accessibility label. The spec is never read or run.
- Visual items stay under the reply when the turn's work is folded, like
image galleries (`TimelineTurn.tsx`).
- Fingerprints are unchanged (`@expo/fingerprint fingerprint:generate`):
iOS `74705db3a68907bc28379bb9b1080a227bc0755b`, Android
`7d38be8f5c9bf842d62060c75820a206f99c87e3`, before and after.
- `expo export` succeeds for iOS and Android; mobile typecheck and
ESLint are clean. Device checks remain blocked (device host), so there
are no on-device screenshots.

The interactive renderer needs `react-native-webview` (the linked
`@expo/dom-webview` can't meet the §4 boundary). Per the plan it ships
later, in one native build with #659.

**Copy audit (docs/copy.md §8):**
| Text | Check |
|---|---|
| Version N | Sentence case, tabular digits, no repeat of the title. |
| Open this visual on web or desktop. | One idea, verb first, says where
it works; no jargon about WebViews or sandboxes. |
| Accessibility label "Visual: <title>, version N. <description> Open
this visual on web or desktop." | Reads the same facts in order;
"visual" per the glossary. |


---
Stack #686 (merge together: `gh stack merge 686 --squash`): #682
spec/kit → #683 gateway → #684 worker → #685 web/desktop → #688 mobile
fallback.

**Merge order:** this stack merges first; migration
`0139_thread_visuals` follows dev's 0138, and the drafts stack moves to
0140. 0139 keeps every tool value of 0138 (`show_images`,
`import_image_reply`) and adds `render_visual`. `Item.visual = 26`
follows `image_gallery = 25`.
@nixuuu
nixuuu force-pushed the feat/mobile-video-player branch from e183387 to 498dd9d Compare November 14, 2026 07:58
@nixuuu
nixuuu marked this pull request as ready for review November 14, 2026 07:58
@nixuuu
nixuuu merged commit 9310537 into dev Nov 14, 2026
16 of 18 checks passed
@nixuuu
nixuuu deleted the feat/mobile-video-player branch November 14, 2026 08:19
nixuuu added a commit that referenced this pull request Nov 14, 2026
Replaces the mobile text-only visual card (#688) with an interactive
renderer in `react-native-webview` **14.0.1** (the version SDK 58 pins).
It ships in the same native build as #659. Do not merge it alone into a
released build: it changes the native fingerprint.

## How it works
- **Same document and CSP as the web.** The app reads the spec with
`GetVisual` (Connect), validates it again and compiles it with
`compileVisual` in frame mode. The WebView gets `source={{ html }}` with
**no `baseUrl`** (an opaque `about:blank` document). It holds a trusted
shell (`@canopy/domain/visual-shell`) that mounts the visual in `<iframe
sandbox="allow-scripts" srcdoc>`, like the web.
- **Shared nonce.** A srcdoc frame inherits its parent's CSP on top of
its own. Headless Chromium showed the kit blocked under the shell's
policy until both documents used the same per-mount nonce.
- **Frame-scoped messaging.** The RN bridge may be reachable from every
frame: Android injects its `WebMessageListener` with `*`, and iOS
exposes `webkit.messageHandlers` to all frames. So the shell wraps each
port message in a per-mount **token envelope** that the frame never
sees. The app drops anything without the token and anything over 8 KiB
plus the envelope. The rest goes through `VisualFrameInbox` (new in
`@canopy/domain/visuals`), which the web `frame-host.ts` now uses too:
10 msg/s, 4 heights/s, strict parser, local state checked against the
spec. Host messages (theme, visibility, reduced motion) go in through
`postMessage` with the same token. The shell accepts them only when
there is no `event.source`, so a frame can't forge them.
- **Locked WebView** (`SandboxedWebView.tsx`):
  - No file, content or universal access.
- `incognito`, no shared or third-party cookies, no DOM storage (the kit
doesn't use it), no cache.
- No new windows: `setSupportMultipleWindows={false}`, a no-op
`onOpenWindow`, `javaScriptCanOpenWindowsAutomatically={false}`. The
shell also disables `window.open`, `alert`, `confirm` and `prompt`.
- No media, geolocation, zoom, link previews or debugging. No
`injectedJavaScript`.
- `originWhitelist={["*"]}` sends every URL to
`onShouldStartLoadWithRequest`. The library's default list would pass
other schemes to `Linking`. That callback allows only the first
top-frame `about:blank` and the child's `about:srcdoc`.
- **Theme** comes from the app theme (light and dark), with Interface
size as the scale, and updates live through host messages.
- **Budget:**
  - At most 1 live WebView in the app.
- A visual mounts lazily when it is on screen and the slot is free.
"Open visual" takes the slot unless the other visual is in full screen.
- Off screen it pauses at once and is released after 5 s. A backgrounded
app releases it at once.
- The last height stays reserved, and a new mount starts at that height.
- Spec cache: LRU, 16 entries / 2 MiB. Control state: 64 entries / 256
KiB in `Paths.cache`.
- **Host chrome at parity:** title, "Version N", "Open full screen" and
"Visual actions". The actions are "Save HTML" (Android, chosen
directory) or "Share HTML" (iOS), "Copy spec", "Cite visual" and the
version list. Full screen uses the same slot, and a hardware Escape
closes it.
- **Old binaries:** `TurboModuleRegistry.get("RNCWebViewModule")` is
checked before the renderer is imported (lazily), so on a build without
the module the JS never touches the native component. Those builds keep
#688's `VisualSummary` card.
- `compileVisualExport` now builds the "Download HTML" file for both the
web BFF route and mobile.

## Verified statically
- `bun install`, `gen:check`, `typecheck`, `lint` (oxlint),
`format:check`, `check:tmp`: 2974 pass, 175 skip, 0 fail, nothing left
in the temp dir. Web build passes.
- New `packages/domain/src/visuals/host.test.ts`:
- The envelope rejects a wrong or missing token, oversized input and
malformed JSON.
  - The inbox enforces its limits and validates state.
- The token is never in the frame document, and the title and spec stay
inert.
- Mounting refuses a newer or revoked kit and a spec that doesn't parse.
- Headless Chromium (Blink, the same engine as Android System WebView),
not committed. From the sandboxed frame:
  - `window.parent.ReactNativeWebView` → SecurityError.
- `window.open` → blocked (no `allow-popups`); `alert` → ignored (no
`allow-modals`).
- `top.location` → SecurityError; `localStorage` and `document.cookie` →
SecurityError; origin `null`.
- A forged token envelope posted to the parent was **not** relayed. The
real `ready` was relayed.
- `expo export` for iOS and Android passes; the shell is in the Hermes
bundle.
- `expo prebuild --no-install --clean` in a temp copy passes:
- No change to Info.plist or app permissions. The library manifest only
merges a non-exported `RNCWebViewFileProvider` and payment `<queries>`;
we turn payment requests off and have no file inputs.
  - The webview is autolinked (`rncoreAutolinkingConfig`).
- **Combined native build (this PR on dev with #659 merged)**,
re-checked on head `e332d33`:
- `bun install --frozen-lockfile` is clean, the mobile typecheck passes,
and `expo export` passes for iOS (3320 modules) and Android (3314
modules).
- `expo prebuild --no-install --clean` in a temp copy passes, and both
sides apply together:
- Autolinking resolves `expo-video`, `canopy-media-stream`,
`canopy-file-intake` and `canopy-pinned-fetch` (Expo modules) plus
`react-native-webview` (RN community).
- #659's `media-network` plugin writes
`res/xml/canopy_media_network.xml`, and `expo-video` adds no
`UIBackgroundModes`.
    - Android permissions and Info.plist keys are unchanged.
  - **Fingerprint** (`@expo/fingerprint`):

    | Platform | dev with #659 | This PR (#659 + webview) |
    | --- | --- | --- |
| iOS | `5a2f1ebbf02efbeb8f57f05a91e105b8f4f7c935` |
`138e0c6b171c82b4933e86808cdfef56da73b8c6` |
| Android | `43b7842311f5520084c7fcfcbce1b1df23da45ec` |
`906dc944f94eb8333fa384ed9f198834fdd30d13` |

The "dev with #659" values come from a temporary worktree that shared
this checkout's `node_modules`. Use the right-hand column for the
scheduled native build.
- `expo lint` on the new files reports the same rule patterns that
already fail across the app (`react-hooks/refs` for `viewport.ref`,
`set-state-in-effect` for claiming the slot). Mobile ESLint is not a CI
gate and already reports 104 errors on dev.

## Security review follow-ups (P3)
- A remount (new shell and token) starts unloaded again: the loaded
state is stored per mount token, so on iOS `allowInitialLoad` no longer
blocks the new `about:blank` (`VisualWebView.tsx`).
- Unpairing, an expired pairing and a new pairing clear the spec cache
and `visual-state.json`, in memory and on disk (`clearVisualCaches` in
`session.tsx`). A read started before a clear can't restore old entries.
- `docs/agent-visuals.md` (mobile section) records the accepted residual
risks: bridge flooding from frame code, and unchecked child-frame
http(s) navigation on Android (the sandbox and CSP stay the boundary).
- Re-checked: oxlint, format, `bun run typecheck`, mobile `tsc`, and
`expo export` for iOS and Android. JS-only change, so the fingerprints
are unchanged.

## Needs on-device checks (the device host is broken)
- **Sandbox boundary on both platforms:** the frame can't reach the
native bridge. The token makes direct calls harmless, but confirm that
Android `WebMessageListener` and iOS `webkit.messageHandlers` calls from
the frame are dropped. Also confirm that no file or content URL loads.
- **Navigation block:** on Android, `shouldOverrideUrlLoading` doesn't
see http(s) navigations of child frames, and it allows the load if JS
doesn't answer within 250 ms. The sandbox and CSP remain the boundary
there; the kit never navigates.
- **Message validation end to end:** heights, saved state restored after
remount, Escape in full screen.
- **Layout:** scrolling inside the iframe within the timeline (iOS
`scrollEnabled={false}` on the shell, Android `nestedScrollEnabled`).
Light and dark, theme changes while open, phone width, long titles.
- **Behaviour:** memory of one WebView (target ≤64 MiB),
VoiceOver/TalkBack, Save/Share HTML, and the fallback card on a build
without the module.

## Copy audit (docs/copy.md §8)
| Text | Check |
|---|---|
| Open visual / Open full screen / Visual actions | Verb first, sentence
case, same as web. |
| Save HTML (Android) / Share HTML (iOS) | Verb matches what the
platform does (save to a chosen folder or share), like "Save image" /
"Share image". |
| Copy spec / Cite visual / Version N / Latest | Same as web; "visual"
per the glossary. |
| Loading visual… / Shown in full screen. | Ongoing action with an
ellipsis; a short status. |
| Couldn't open this visual. + Retry | What happened; the button is the
action. |
| Update Canopy to open this visual. | One idea, says what to do. |
| Close another visual to open this one. | Imperative, says what to do.
|
| Couldn't save/share the HTML. Try again. / Couldn't copy the spec. Try
again. / Couldn't cite this visual. Try again. | What happened, then
what to do. |
| Spec copied | Short status, no period. |

No new glossary terms.
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