@scarlett-player/captions 1.4.0 → 1.4.1

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
@@ -30,7 +30,6 @@ function createCaptionsPlugin(config = {}) {
30
30
  let api = null;
31
31
  let video = null;
32
32
  let addedTrackElements = [];
33
- let hlsTrackElements = [];
34
33
  let hlsSubtitleHandler = null;
35
34
  let observedTextTracks = null;
36
35
  let hlsRetryTimer = null;
@@ -49,18 +48,10 @@ function createCaptionsPlugin(config = {}) {
49
48
  trackEl.parentNode?.removeChild(trackEl);
50
49
  }
51
50
  addedTrackElements = [];
52
- hlsTrackElements = [];
53
51
  api?.setState("textTracks", []);
54
52
  api?.setState("currentTextTrack", null);
55
53
  };
56
- const removeHlsTrackElements = () => {
57
- for (const trackEl of hlsTrackElements) {
58
- trackEl.parentNode?.removeChild(trackEl);
59
- addedTrackElements = addedTrackElements.filter((el) => el !== trackEl);
60
- }
61
- hlsTrackElements = [];
62
- };
63
- const addTrackElement = (source, origin = "config") => {
54
+ const addTrackElement = (source) => {
64
55
  const videoEl = getVideo();
65
56
  if (!videoEl) throw new Error("No video element");
66
57
  const trackEl = document.createElement("track");
@@ -71,9 +62,6 @@ function createCaptionsPlugin(config = {}) {
71
62
  trackEl.default = false;
72
63
  videoEl.appendChild(trackEl);
73
64
  addedTrackElements.push(trackEl);
74
- if (origin === "hls") {
75
- hlsTrackElements.push(trackEl);
76
- }
77
65
  if (trackEl.track) {
78
66
  trackEl.track.mode = "disabled";
79
67
  }
@@ -161,21 +149,9 @@ function createCaptionsPlugin(config = {}) {
161
149
  if (!hlsPlugin || hlsPlugin.isNativeHLS()) return;
162
150
  const hlsInstance = hlsPlugin.getHlsInstance();
163
151
  if (!hlsInstance?.subtitleTracks?.length) return;
164
- api.logger.debug("Extracting HLS subtitle tracks", {
152
+ api.logger.debug("Syncing HLS subtitle tracks", {
165
153
  count: hlsInstance.subtitleTracks.length
166
154
  });
167
- removeHlsTrackElements();
168
- for (const hlsTrack of hlsInstance.subtitleTracks) {
169
- addTrackElement(
170
- {
171
- language: hlsTrack.lang || "unknown",
172
- label: hlsTrack.name || `Subtitle ${hlsTrack.id}`,
173
- src: hlsTrack.url,
174
- kind: "subtitles"
175
- },
176
- "hls"
177
- );
178
- }
179
155
  syncTracksToState();
180
156
  maybeAutoSelect();
181
157
  };
@@ -212,7 +188,7 @@ function createCaptionsPlugin(config = {}) {
212
188
  const initSources = () => {
213
189
  if (!config.sources?.length) return;
214
190
  for (const source of config.sources) {
215
- addTrackElement(source, "config");
191
+ addTrackElement(source);
216
192
  }
217
193
  };
218
194
  return {
package/dist/index.js CHANGED
@@ -5,7 +5,6 @@ function createCaptionsPlugin(config = {}) {
5
5
  let api = null;
6
6
  let video = null;
7
7
  let addedTrackElements = [];
8
- let hlsTrackElements = [];
9
8
  let hlsSubtitleHandler = null;
10
9
  let observedTextTracks = null;
11
10
  let hlsRetryTimer = null;
@@ -24,18 +23,10 @@ function createCaptionsPlugin(config = {}) {
24
23
  trackEl.parentNode?.removeChild(trackEl);
25
24
  }
26
25
  addedTrackElements = [];
27
- hlsTrackElements = [];
28
26
  api?.setState("textTracks", []);
29
27
  api?.setState("currentTextTrack", null);
30
28
  };
31
- const removeHlsTrackElements = () => {
32
- for (const trackEl of hlsTrackElements) {
33
- trackEl.parentNode?.removeChild(trackEl);
34
- addedTrackElements = addedTrackElements.filter((el) => el !== trackEl);
35
- }
36
- hlsTrackElements = [];
37
- };
38
- const addTrackElement = (source, origin = "config") => {
29
+ const addTrackElement = (source) => {
39
30
  const videoEl = getVideo();
40
31
  if (!videoEl) throw new Error("No video element");
41
32
  const trackEl = document.createElement("track");
@@ -46,9 +37,6 @@ function createCaptionsPlugin(config = {}) {
46
37
  trackEl.default = false;
47
38
  videoEl.appendChild(trackEl);
48
39
  addedTrackElements.push(trackEl);
49
- if (origin === "hls") {
50
- hlsTrackElements.push(trackEl);
51
- }
52
40
  if (trackEl.track) {
53
41
  trackEl.track.mode = "disabled";
54
42
  }
@@ -136,21 +124,9 @@ function createCaptionsPlugin(config = {}) {
136
124
  if (!hlsPlugin || hlsPlugin.isNativeHLS()) return;
137
125
  const hlsInstance = hlsPlugin.getHlsInstance();
138
126
  if (!hlsInstance?.subtitleTracks?.length) return;
139
- api.logger.debug("Extracting HLS subtitle tracks", {
127
+ api.logger.debug("Syncing HLS subtitle tracks", {
140
128
  count: hlsInstance.subtitleTracks.length
141
129
  });
142
- removeHlsTrackElements();
143
- for (const hlsTrack of hlsInstance.subtitleTracks) {
144
- addTrackElement(
145
- {
146
- language: hlsTrack.lang || "unknown",
147
- label: hlsTrack.name || `Subtitle ${hlsTrack.id}`,
148
- src: hlsTrack.url,
149
- kind: "subtitles"
150
- },
151
- "hls"
152
- );
153
- }
154
130
  syncTracksToState();
155
131
  maybeAutoSelect();
156
132
  };
@@ -187,7 +163,7 @@ function createCaptionsPlugin(config = {}) {
187
163
  const initSources = () => {
188
164
  if (!config.sources?.length) return;
189
165
  for (const source of config.sources) {
190
- addTrackElement(source, "config");
166
+ addTrackElement(source);
191
167
  }
192
168
  };
193
169
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scarlett-player/captions",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
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.4.0"
33
+ "@scarlett-player/core": "1.4.1"
34
34
  },
35
35
  "keywords": [
36
36
  "video",