Skip to content

fix: let only the latest subscription detach a camera track - #1

Merged
Magmusacy merged 1 commit into
fishjam-cloud:mainfrom
Critteros:fix/stale-subscription-detach
Nov 12, 2026
Merged

Magmusacy merged 1 commit into
fishjam-cloud:mainfrom
Critteros:fix/stale-subscription-detach

Conversation

@Critteros

Copy link
Copy Markdown
Contributor

Problem

When a camera effect directly replaces another effect on the same track, the new effect gets no frames. Its video stops on the last frame. The changes effect -> null and null -> effect work

Cause

image
  1. applyMiddleware in @fishjam-cloud/react-client starts the new effect, publishes it, then stops the old effect.
  2. The old effect calls subscription.remove(), and remove() always calls processor.detach().
  3. The native tap has one consumer slot per track, and detach() does not know which consumer calls it. It removes the new consumer and the tap of the track:
    • iOS: fj_detachTrackIdOnWorkerQueue and CameraFrameTap.detachConsumer
    • Android: TrackPrivate.releaseCameraFrameTap
  4. The activeSubscriptions guard does not stop this. Its key is the processor handle, and getCameraFrameProcessor returns a new handle on each call.

Fix

Only the latest subscription of a track can detach. An older subscription still clears its own callback.

 remove()
   clear activeSubscriptions entry
-  processor.detach()
+  if latestSubscriptionByTrack[trackId] is this subscription
+    delete the entry
+    processor.detach()
   clear the callback

 attachCameraFrameCallback()
   processor.attach(consumer)
+  latestSubscriptionByTrack[trackId] = subscription

The map changes on the same JS tick as processor.attach, so it follows the order of the native slot. A failed attach does not change the map

A track has one native consumer slot, shared by all processor
handles. react-client starts the new effect before it stops the old
one, so remove() on the old subscription emptied the slot and froze
the video. Detach only from the latest subscription of the track.
@Magmusacy
Magmusacy self-requested a review November 5, 2026 11:51

@Magmusacy Magmusacy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

good job

@Magmusacy
Magmusacy merged commit 6efbd15 into fishjam-cloud:main Nov 12, 2026
3 checks passed
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.

2 participants