Menu ▾ ▴

#72 Track in-call state with a live-track counter instead of the global __carrierInCall boolean

closed
nobody
2026-07-18
2026-07-06
Anonymous
No

Originally created by: kristofferR

Split out from the [#48] review (PR [#70]).

Problem

inject/src/messenger/features/media-permissions.ts sets window.__carrierInCall = true when getUserMedia succeeds and clears it from each track's ended event. Auto-refresh reads this flag so it never reloads the page mid-call. Two issues:

  1. Stuck-true on normal teardown. MediaStreamTrack.stop() does not fire ended (per spec — ended is only for external termination like a revoked permission or hardware disconnect). A normal hangup that stops tracks can therefore leave __carrierInCall stuck true, blocking auto-refresh indefinitely.
  2. Cleared too early on overlap. The flag is a single global boolean, so if two calls overlap, the first call ending can clear it while the second is still live.

Why it's a separate issue

Pre-existing behavior, transcribed verbatim in PR [#70]'s no-behavior-change refactor. CodeRabbit rated it a "heavy lift" and agreed it was reasonable to defer — a correct fix is a small redesign, not a one-liner, and needs camera/mic testing.

Fix sketch

Replace the boolean with a shared live-track counter:

  • Increment per live track obtained from getUserMedia.
  • Decrement on every cleanup path — ended, and an explicit stop/teardown wrapper (e.g. patch MediaStreamTrack.stop to decrement, or observe track readyState) — guarding against double-decrement.
  • __carrierInCall becomes counter > 0.

Verify a normal hangup clears the state (auto-refresh resumes) and that overlapping calls don't clear it prematurely.

Ref [#48]

Related

Tickets: #140
Tickets: #48
Tickets: #70

Discussion

  • Anonymous

    Anonymous - 2026-07-18

    Ticket changed by: kristofferR

    • status: open --> closed
     
  • Anonymous

    Anonymous - 2026-07-18

    Originally posted by: kristofferR

    Fixed in [#140]. In-call state is now tracked with a live media-track counter instead of the global __carrierInCall boolean.

     

    Related

    Tickets: #140


Log in to post a comment.