Fix Android playground auto-connect and scrcpy preview race#2285
Fix Android playground auto-connect and scrcpy preview race#2285
Conversation
Deploying midscene with
|
| Latest commit: |
38a37b1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ee3f742c.midscene.pages.dev |
| Branch Preview URL: | https://codex-fix-android-playground.midscene.pages.dev |
Produce ScrcpyMediaStreamPacket from @yume-chan/scrcpy directly so videoStream.pipeTo(decoder.writable) type-checks during declaration file generation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 07eee6c160
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!created) { | ||
| autoCreateSignatureRef.current = null; |
There was a problem hiding this comment.
Prevent infinite auto-create retries after session create failure
When createSession(autoCreateInput, { silent: true }) fails, this branch clears autoCreateSignatureRef, so the next render recomputes the same signature and immediately retries again. In a persistent failure case (e.g., stale/unauthorized device), the effect loops indefinitely, repeatedly hitting createSession and surfacing error toasts, which can flood both the backend and UI until the user refreshes or manually disables auto-create.
Useful? React with 👍 / 👎.
- Rename the keyframe field read from the raw socket payload to keyFrame so it matches what the android-playground server actually emits; the flag now reaches the decoder instead of being silently dropped. - Drop the wall-clock-derived pts: BigInt(Date.now()) on data packets. The scrcpy decoder expects a device PTS in microseconds, so feeding it millisecond wall-clock values was semantically wrong. With no reliable source, leave pts undefined and let the decoder render in arrival order, matching the pre-existing behaviour. - Remove the now-unused timestamp field from RawScrcpyVideoPacket. - Add a vitest script and devDependency to @midscene/playground-app so the previously orphaned tests/ directory actually runs, and extend scrcpy-stream.test.ts with coverage for keyFrame propagation and the pts-is-undefined contract.
Summary
Root cause
video-datalistener aftervideo-metadata, so the first configuration packet could be missed and the decoder could stay stuck on the loading state until a full refreshImpact
Validation
pnpm run lintcd packages/playground-app && ../playground/node_modules/.bin/vitest run -c vitest.config.tscd packages/android-playground && ../android/node_modules/.bin/vitest run -c vitest.config.tsnpx nx build @midscene/playgroundnpx nx build @midscene/android-playgroundNotes
packages/playground-appstill has existing upstream build/type issues unrelated to this change, so I validated the affected app package with package-local tests instead of a full workspace build for that target.