Skip to content

Fix lost camera after reconnect#901

Merged
pblazej merged 2 commits intomainfrom
blaze/fix-lost-camera
Feb 10, 2026
Merged

Fix lost camera after reconnect#901
pblazej merged 2 commits intomainfrom
blaze/fix-lost-camera

Conversation

@pblazej
Copy link
Copy Markdown
Contributor

@pblazej pblazej commented Feb 2, 2026

Resolves #898

Currently, there's no way to prevent this fallback to .first:

device = devices.first { $0.position == self.options.position } ?? devices.first

which may be unstable. This is very "narrow" fix, hard to tell more without debug logs.

Should not affect any other paths than the fallback (options are stored, see below).

Alternative solution

Persist device (position) even with empty options across cleanups around:

// Reset state
_cameraCapturerState.mutate { $0 = State(options: $0.options) }

Scenario assuming .unspecified default:

1. First start — front camera selected with .unspecified position:
  2026-02-02 10:39:59.822 → starting camera capturer device: <AVCaptureFigVideoDevice: 0x12103e800
    [前置相机][com.apple.avfoundation.avcapturedevice.built-in_video:1]>, format: (format: 'vide'/'420v'
    1280x 720, { 1- 60 fps}, photo dims:{1280x720,2016x1136}, fov:73.292, binned, supports vis
    (max strength:Low), max zoom:24.00 (upscales @1.43), ISO:23.0-2208.0, SS:0.000022-1.000000,
    supports multicam, supports Portrait Effect, dimensions: Dimensions(1280x720)), fps: 24(0...60)

  2. Quick reconnect fails:
  2026-02-02 10:39:59.925 → [Connect] Reconnect mode: .quick failed with error:
    Error Domain=io.livekit.swift-sdk Code=100 "Cancelled" UserInfo={NSLocalizedDescription=Cancelled}

  3. Full reconnect starts:
  2026-02-02 10:40:00.983 → [Connect] starting .full reconnect sequence...
  2026-02-02 10:40:00.984 → withError: nil, isFullReconnect: true

  4. Unpublish fails on old publisher (track.stop() skipped, capturer not reset):
  2026-02-02 10:40:01.040 → Failed to unpublish track TR_VCxN3W8S9ufxhK with error
    Error Domain=io.livekit.swift-sdk Code=201 "WebRTC error(Failed to remove track)"
  2026-02-02 10:40:01.041 → captureState is not .stopped, capturer must be stopped before deinit.

  5. Full reconnect succeeds:
  2026-02-02 10:40:02.239 → [Connect] Full reconnect succeeded for attempt 2

  6. Same capturer restarts — rear camera selected, still .unspecified:
  2026-02-02 10:40:02.277 → starting camera capturer device: <AVCaptureFigVideoDevice: 0x12103ac00
    [后置双广角镜头][com.apple.avfoundation.avcapturedevice.built-in_video:6]>, format: (format:
    'vide'/'420v' 1280x 720, { 1- 30 fps}, photo dims:{1280x720,4224x2376}, fov:107.803, gdc
    fov:100.567, supports vis (max strength:Low), max zoom:123.75 (upscales @3.00), AF System:2,
    ISO:32.0-3072.0, SS:0.000018-1.000000, supports HDR, supports depth, supports multicam, supports
    high photo quality, dimensions: Dimensions(1280x720)), fps: 24(0...30)

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 2, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch blaze/fix-lost-camera

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 2, 2026

⚠️ This PR does not contain any files in the .changes directory.

@pblazej pblazej force-pushed the blaze/fix-lost-camera branch from c71e9f7 to 4fce45d Compare February 10, 2026 10:07
@pblazej pblazej force-pushed the blaze/fix-lost-camera branch from 4fce45d to 4600f97 Compare February 10, 2026 10:29
@pblazej pblazej marked this pull request as ready for review February 10, 2026 13:01
@pblazej pblazej requested a review from hiroshihorie February 10, 2026 13:01
@pblazej pblazej merged commit 8ceea94 into main Feb 10, 2026
47 of 49 checks passed
@pblazej pblazej deleted the blaze/fix-lost-camera branch February 10, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants