fix(web): forward cues that already exist when a text track is added - #891
fix(web): forward cues that already exist when a text track is added#891tvanlaerhoven wants to merge 4 commits into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
daf590e to
f66dde5
Compare
9504684 to
461c47e
Compare
461c47e to
de6d634
Compare
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
de6d634 to
8417b98
Compare
| track.addEventListener('addcue', listeners.addcue); | ||
| track.addEventListener('removecue', listeners.removecue); | ||
| track.addEventListener('entercue', listeners.entercue); | ||
| track.addEventListener('exitcue', listeners.exitcue); | ||
| this._facade.dispatchEvent(new DefaultTextTrackListEvent(TrackListEventType.ADD_TRACK, fromNativeTextTrack(track))); | ||
| track.cues?.forEach((cue) => { | ||
| this._facade.dispatchEvent(new DefaultTextTrackEvent(TextTrackEventType.ADD_CUE, track.uid, fromNativeCue(cue))); | ||
| }); |
There was a problem hiding this comment.
📝 Info: Pre-existing cues do not get entercue replay
Only ADD_CUE is replayed. If a cue that already exists at addtrack time is currently active (playhead inside its interval), no ENTER_CUE is forwarded because the native entercue fired before the listener was attached — the same class of gap the PR fixes for addcue. Consumers relying on ENTER_CUE for daterange handling on iOS Safari may still miss the first cue.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
True — a cue already active at addtrack time gets no ENTER_CUE replay. Deliberately left out of this PR: replaying it correctly would need to consult track.activeCues (activeness, not just existence), and unconditionally synthesizing ENTER_CUE risks firing it for cues that aren't active, which is worse than the gap. ADD_CUE replay delivers the cue payload (including daterange data), which is what the reported issue needed. Can follow up with an activeCues-based ENTER_CUE replay if a consumer turns out to depend on it.
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
Summary
WebEventForwarder.onAddTextTrackattached the track-leveladdcuelistener only whenaddtrackfired, so any cue already present on the track at that moment produced no player-levelTEXT_TRACK/addcueevent. On iOS Safari the web SDK populates daterange cues before firingaddtrack, so consumers listening onPlayerEventType.TEXT_TRACKnever received them (the cues were only visible viaevent.track.cueson theTEXT_TRACK_LISTevent).Fix: after dispatching
ADD_TRACK, replay the cues already on the track asADD_CUEplayer events. Their uids are remembered so a nativeaddcuearriving later for one of those same cues is not forwarded twice; a uid is dropped from that set onremovecue, so a genuine remove/re-add still forwards. The set only ever holds cues that existed ataddtracktime — cues arriving afterwards are forwarded with no bookkeeping.dispatchEvent(ADD_TRACK, fromNativeTextTrack(track)); + track.cues?.forEach((cue) => dispatchEvent(ADD_CUE, track.uid, fromNativeCue(cue)));Second, unrelated-but-adjacent fix: track listener removal never worked.
onRemoveTextTrack/onRemoveMediaTrackcalledremoveEventListenerwith a freshly created closure (this.onAddTextTrackCue(track)), a different function identity than the one registered — so cue andactivequalitychangedlisteners stayed attached for the life of the player, leaking and dispatching events for removed tracks. The listeners are now kept per track uid and the exact registered reference is removed;removeEventListeners()also detaches tracks that were never explicitly removed.Note the same attach-on-
ADD_TRACKpattern exists in the iOS (THEOplayerRCTTextTrackEventHandler) and Android (PlayerEventEmitter) handlers; those are left alone since the native SDKs fireaddcueafteraddtrack.Verification
No JS test framework exists in this repo, so this was verified with a standalone script driving the compiled forwarder against a fake player/track emitter, covering: cues present at
addtrackare forwarded afterADD_TRACK; a duplicate nativeaddcuefor a replayed cue is suppressed; remove-then-re-add of the same cue is forwarded again; no cue events afterremovetrack.npm run lint,npm run prettierandtsc -p tsconfig.build.jsonpass.Link to Devin session: https://dolby.devinenterprise.com/sessions/fc9bf7b3e83e4f2bafb75a3d70edcb3c
Requested by: @tvanlaerhoven