Skip to content

fix: restore camera when screen-picker is canceled#272

Merged
JohnMcLear merged 1 commit intomainfrom
fix/screenshare-cancel-restores-camera
May 1, 2026
Merged

fix: restore camera when screen-picker is canceled#272
JohnMcLear merged 1 commit intomainfrom
fix/screenshare-cancel-restores-camera

Conversation

@JohnMcLear
Copy link
Copy Markdown
Member

Summary

Clicking the screenshare button when the camera is on, then clicking Cancel in the OS screen-picker, used to leave the user with no video at all (camera button stuck off, stale disabled camera track in the local stream).

Bug

addAsyncEventHandlers($screenshareBtn, ...) in static/js/index.js did:

this._selfViewButtons.video.enabled = false;            // turn camera button off
this._selfViewButtons.screenshare.enabled = true;
await this.updateLocalTracks({updateVideo: true});      // calls getDisplayMedia

If getDisplayMedia rejects (user clicks Cancel → NotAllowedError, or browser denies):

  • updateLocalTracks flips screenshare.enabled back to false.
  • But the camera button is still off (we set it sync, before the await).
  • The OLD camera track in _localTracks.stream is now disabled (loop on line 692-694 sets track.enabled = video.enabled which is false).
  • User sees: both buttons off, no video, but camera light may still be on (track is live but disabled).

Fix

Capture the camera's previous state. After updateLocalTracks, if the user wanted to enable screenshare and screenshare didn't take and the camera was on before, re-enable the camera button and call updateLocalTracks({updateVideo: true}) once more so the camera track ends up enabled + live again.

Test

New static/tests/frontend-new/specs/screenshare.spec.ts:

  • Camera-on scenario: stub getDisplayMedia to throw NotAllowedError → click screenshare → assert camera button on, screenshare button off, video track live + enabled.
  • Camera-off scenario: turn camera off, click screenshare, cancel → assert both buttons stay off (we don't auto-enable a camera the user explicitly turned off).

Couldn't run locally — my etherpad-lite checkout is on a feature branch whose playwright.config.ts doesn't auto-discover plugin specs. CI on develop has the right test-match config.

Semver: patch

Bug fix.

Test plan

  • CI: new screenshare.spec.ts passes (2 cases) and existing suite stays green
  • Manual smoke: pad with camera enabled → click screenshare button → click Cancel in picker → camera should still show live video, camera button should be on, screenshare button should be off

🤖 Generated with Claude Code

Clicking the screenshare button calls getDisplayMedia(). If the user
clicks Cancel in the OS picker (or denies permission), getDisplayMedia
rejects with NotAllowedError. The previous handler unconditionally
flipped the camera button to off BEFORE awaiting getDisplayMedia, and
when the picker was canceled the rejected screenshare path left the
camera button stuck off — with a stale, disabled camera track still
sitting in the local stream. The user saw 'no video' even though the
camera was previously running.

Capture the camera's previous state, attempt screenshare, and if
screenshare didn't take AND the camera was on before, re-enable the
camera button + run updateLocalTracks again to restore live video.

Includes a regression test in
static/tests/frontend-new/specs/screenshare.spec.ts that stubs
getDisplayMedia to throw NotAllowedError, clicks the screenshare
button, and asserts both the button state AND the underlying video
track end up live + enabled. Also covers the case where the camera
was off before the click — both buttons stay off in that case (we
don't auto-enable a camera the user explicitly turned off).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@JohnMcLear
Copy link
Copy Markdown
Member Author

/review

@qodo-code-review
Copy link
Copy Markdown

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

1 similar comment
@qodo-code-review
Copy link
Copy Markdown

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@JohnMcLear JohnMcLear merged commit d9e1114 into main May 1, 2026
3 checks passed
@JohnMcLear JohnMcLear deleted the fix/screenshare-cancel-restores-camera branch May 1, 2026 09:33
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