Skip to content

Conversation

@gamerg21
Copy link
Owner

Motivation

  • Provide users with an explicit way to choose between multiple cameras (front/rear) when the device exposes more than one video input.
  • Improve reliability when the browser randomly chooses a camera by allowing an immediate manual switch.

Description

  • Track available cameras with videoDevices and store the active camera in selectedDeviceId in BarcodeScanner.tsx.
  • Add a Switch camera button (with RefreshCcw icon) that cycles the selected device via handleSwitchCamera when more than one camera is present.
  • Restart the decoder when the selected camera changes by adding selectedDeviceId to the scanner useEffect dependencies and resetting the reader before reinitializing.
  • Preserve the existing fallback behavior for environments that don't support device enumeration (e.g., iOS Safari) by falling back to the browser default camera.

Testing

  • Ran type checking with npm run type-check which executed tsc --noEmit and passed.
  • No other automated tests were added or run for this change.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ 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".

Comment on lines 69 to +72
if (videoRef.current) {
codeReader.reset();
const activeDeviceId = selectedDeviceId ?? availableDevices[0]?.deviceId ?? null;

Choose a reason for hiding this comment

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

P2 Badge Fall back when selected camera is no longer available

The scanner now always prefers selectedDeviceId, but that value is persisted across openings and not checked against the freshly enumerated availableDevices. If the previously chosen camera was unplugged or permissions changed, decodeFromVideoDevice will be called with a stale device id and won’t fall back to the default camera, leaving the scanner stuck. Consider validating that selectedDeviceId still exists in availableDevices (or resetting it) before choosing activeDeviceId.

Useful? React with 👍 / 👎.

@gamerg21 gamerg21 merged commit 4cf1b55 into main Dec 25, 2025
2 checks passed
@gamerg21 gamerg21 deleted the codex/add-camera-switch-button-functionality branch December 25, 2025 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants