@scarlett-player/captions 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -26,16 +26,18 @@ __export(index_exports, {
26
26
  module.exports = __toCommonJS(index_exports);
27
27
 
28
28
  // src/version.ts
29
- var PKG_VERSION = true ? "1.9.0" : "0.0.0-dev";
29
+ var PKG_VERSION = true ? "1.10.0" : "0.0.0-dev";
30
30
 
31
31
  // src/index.ts
32
32
  var HLS_SUBTITLE_TRACKS_UPDATED = "hlsSubtitleTracksUpdated";
33
+ var HLS_SUBTITLE_TRACK_SWITCH = "hlsSubtitleTrackSwitch";
33
34
  var HLS_INSTANCE_RETRY_MS = 500;
34
35
  function createCaptionsPlugin(config = {}) {
35
36
  let api = null;
36
37
  let video = null;
37
38
  let addedTrackElements = [];
38
39
  let hlsSubtitleHandler = null;
40
+ let hlsSubtitleSwitchHandler = null;
39
41
  let observedTextTracks = null;
40
42
  let hlsRetryTimer = null;
41
43
  let hlsRetryUsed = false;
@@ -165,10 +167,16 @@ function createCaptionsPlugin(config = {}) {
165
167
  clearTimeout(hlsRetryTimer);
166
168
  hlsRetryTimer = null;
167
169
  }
168
- if (!hlsSubtitleHandler) return;
170
+ if (!hlsSubtitleHandler && !hlsSubtitleSwitchHandler) return;
169
171
  const hlsInstance = api?.getPlugin("hls-provider")?.getHlsInstance();
170
- hlsInstance?.off(HLS_SUBTITLE_TRACKS_UPDATED, hlsSubtitleHandler);
171
- hlsSubtitleHandler = null;
172
+ if (hlsSubtitleHandler) {
173
+ hlsInstance?.off(HLS_SUBTITLE_TRACKS_UPDATED, hlsSubtitleHandler);
174
+ hlsSubtitleHandler = null;
175
+ }
176
+ if (hlsSubtitleSwitchHandler) {
177
+ hlsInstance?.off(HLS_SUBTITLE_TRACK_SWITCH, hlsSubtitleSwitchHandler);
178
+ hlsSubtitleSwitchHandler = null;
179
+ }
172
180
  };
173
181
  const syncFromHls = () => {
174
182
  if (!extractFromHLS || !api) return;
@@ -188,6 +196,8 @@ function createCaptionsPlugin(config = {}) {
188
196
  unsubscribeFromHls();
189
197
  hlsSubtitleHandler = () => extractHlsSubtitles();
190
198
  hlsInstance.on(HLS_SUBTITLE_TRACKS_UPDATED, hlsSubtitleHandler);
199
+ hlsSubtitleSwitchHandler = () => syncTracksToState();
200
+ hlsInstance.on(HLS_SUBTITLE_TRACK_SWITCH, hlsSubtitleSwitchHandler);
191
201
  extractHlsSubtitles();
192
202
  };
193
203
  const initSources = () => {
package/dist/index.d.cts CHANGED
@@ -34,7 +34,8 @@ interface CaptionsPluginConfig {
34
34
  * Provides WebVTT subtitle/caption support with:
35
35
  * - External WebVTT file loading via <track> elements
36
36
  * - HLS.js subtitle track extraction, driven by Hls.Events.SUBTITLE_TRACKS_UPDATED
37
- * (emitted as 'hlsSubtitleTracksUpdated')
37
+ * (emitted as 'hlsSubtitleTracksUpdated'), and state resync on
38
+ * Hls.Events.SUBTITLE_TRACK_SWITCH (emitted as 'hlsSubtitleTrackSwitch')
38
39
  * - Native HLS support (Safari/iOS) by observing the video's TextTrackList
39
40
  * - Browser-native rendering (no custom VTT parser)
40
41
  * - State sync with core textTracks/currentTextTrack
package/dist/index.d.ts CHANGED
@@ -34,7 +34,8 @@ interface CaptionsPluginConfig {
34
34
  * Provides WebVTT subtitle/caption support with:
35
35
  * - External WebVTT file loading via <track> elements
36
36
  * - HLS.js subtitle track extraction, driven by Hls.Events.SUBTITLE_TRACKS_UPDATED
37
- * (emitted as 'hlsSubtitleTracksUpdated')
37
+ * (emitted as 'hlsSubtitleTracksUpdated'), and state resync on
38
+ * Hls.Events.SUBTITLE_TRACK_SWITCH (emitted as 'hlsSubtitleTrackSwitch')
38
39
  * - Native HLS support (Safari/iOS) by observing the video's TextTrackList
39
40
  * - Browser-native rendering (no custom VTT parser)
40
41
  * - State sync with core textTracks/currentTextTrack
package/dist/index.js CHANGED
@@ -1,14 +1,16 @@
1
1
  // src/version.ts
2
- var PKG_VERSION = true ? "1.9.0" : "0.0.0-dev";
2
+ var PKG_VERSION = true ? "1.10.0" : "0.0.0-dev";
3
3
 
4
4
  // src/index.ts
5
5
  var HLS_SUBTITLE_TRACKS_UPDATED = "hlsSubtitleTracksUpdated";
6
+ var HLS_SUBTITLE_TRACK_SWITCH = "hlsSubtitleTrackSwitch";
6
7
  var HLS_INSTANCE_RETRY_MS = 500;
7
8
  function createCaptionsPlugin(config = {}) {
8
9
  let api = null;
9
10
  let video = null;
10
11
  let addedTrackElements = [];
11
12
  let hlsSubtitleHandler = null;
13
+ let hlsSubtitleSwitchHandler = null;
12
14
  let observedTextTracks = null;
13
15
  let hlsRetryTimer = null;
14
16
  let hlsRetryUsed = false;
@@ -138,10 +140,16 @@ function createCaptionsPlugin(config = {}) {
138
140
  clearTimeout(hlsRetryTimer);
139
141
  hlsRetryTimer = null;
140
142
  }
141
- if (!hlsSubtitleHandler) return;
143
+ if (!hlsSubtitleHandler && !hlsSubtitleSwitchHandler) return;
142
144
  const hlsInstance = api?.getPlugin("hls-provider")?.getHlsInstance();
143
- hlsInstance?.off(HLS_SUBTITLE_TRACKS_UPDATED, hlsSubtitleHandler);
144
- hlsSubtitleHandler = null;
145
+ if (hlsSubtitleHandler) {
146
+ hlsInstance?.off(HLS_SUBTITLE_TRACKS_UPDATED, hlsSubtitleHandler);
147
+ hlsSubtitleHandler = null;
148
+ }
149
+ if (hlsSubtitleSwitchHandler) {
150
+ hlsInstance?.off(HLS_SUBTITLE_TRACK_SWITCH, hlsSubtitleSwitchHandler);
151
+ hlsSubtitleSwitchHandler = null;
152
+ }
145
153
  };
146
154
  const syncFromHls = () => {
147
155
  if (!extractFromHLS || !api) return;
@@ -161,6 +169,8 @@ function createCaptionsPlugin(config = {}) {
161
169
  unsubscribeFromHls();
162
170
  hlsSubtitleHandler = () => extractHlsSubtitles();
163
171
  hlsInstance.on(HLS_SUBTITLE_TRACKS_UPDATED, hlsSubtitleHandler);
172
+ hlsSubtitleSwitchHandler = () => syncTracksToState();
173
+ hlsInstance.on(HLS_SUBTITLE_TRACK_SWITCH, hlsSubtitleSwitchHandler);
164
174
  extractHlsSubtitles();
165
175
  };
166
176
  const initSources = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scarlett-player/captions",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Captions Plugin for Scarlett Player - WebVTT subtitles and closed captions",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -30,7 +30,7 @@
30
30
  "tsup": "^8.5.1",
31
31
  "typescript": "^5.3.0",
32
32
  "vitest": "^1.6.0",
33
- "@scarlett-player/core": "1.9.0"
33
+ "@scarlett-player/core": "1.10.0"
34
34
  },
35
35
  "keywords": [
36
36
  "video",