bigscreen-player 5.6.2 → 5.6.5

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.
@@ -1,7 +1,7 @@
1
1
  import { fromXML, generateISD, renderHTML } from 'smp-imsc';
2
- import { b as TimeUtils, L as LoadUrl, a as DebugTool, P as Plugins, U as Utils, D as DOMHelpers } from './main-61b49de6.js';
2
+ import { b as TimeUtils, L as LoadUrl, a as DebugTool, P as Plugins, U as Utils, D as DOMHelpers } from './main-ba52ef8f.js';
3
3
 
4
- function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, defaultStyleOpts) {
4
+ function IMSCSubtitles(mediaPlayer, autoStart, parentElement, mediaSources, defaultStyleOpts) {
5
5
  const SEGMENTS_TO_KEEP = 3;
6
6
  const liveSubtitles = !!mediaSources.currentSubtitlesSegmentLength();
7
7
  const LOAD_ERROR_COUNT_MAX = 3;
@@ -20,11 +20,14 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
20
20
  start();
21
21
  }
22
22
 
23
- function loadAllRequiredSegments () {
23
+ function loadAllRequiredSegments() {
24
24
  const segmentsToLoad = [];
25
- const currentSegment = TimeUtils.calculateSegmentNumber(windowStartEpochSeconds + mediaPlayer.getCurrentTime(), mediaSources.currentSubtitlesSegmentLength());
26
- for (let i = 0; i < SEGMENTS_TO_KEEP; i++) {
27
- const segmentNumber = currentSegment + i;
25
+ const currentSegment = TimeUtils.calculateSegmentNumber(
26
+ windowStartEpochSeconds + mediaPlayer.getCurrentTime(),
27
+ mediaSources.currentSubtitlesSegmentLength()
28
+ );
29
+ for (let index = 0; index < SEGMENTS_TO_KEEP; index++) {
30
+ const segmentNumber = currentSegment + index;
28
31
  const alreadyLoaded = segments.some((segment) => segment.number === segmentNumber);
29
32
 
30
33
  if (!alreadyLoaded) {
@@ -43,56 +46,56 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
43
46
  });
44
47
  }
45
48
 
46
- function loadSegment (url, segmentNumber) {
47
- url = url.replace('$segment$', segmentNumber);
48
- LoadUrl(url, {
49
+ function loadSegment(url, segmentNumber) {
50
+ const segmentUrl = url.replace("$segment$", segmentNumber);
51
+ LoadUrl(segmentUrl, {
49
52
  timeout: mediaSources.subtitlesRequestTimeout(),
50
- onLoad: (responseXML, responseText, status) => {
53
+ onLoad: (responseXML, responseText) => {
51
54
  resetLoadErrorCount();
52
55
  if (!responseXML && !liveSubtitles) {
53
- DebugTool.info('Error: responseXML is invalid.');
56
+ DebugTool.info("Error: responseXML is invalid.");
54
57
  Plugins.interface.onSubtitlesXMLError({ cdn: mediaSources.currentSubtitlesCdn() });
55
58
  stop();
56
59
  return
57
60
  }
58
61
 
59
62
  try {
60
- const xml = fromXML(responseText.split(/<\?xml[^\?]+\?>/i)[1] || responseText);
63
+ const xml = fromXML(responseText.split(/<\?xml[^?]+\?>/i)[1] || responseText);
61
64
  const times = xml.getMediaTimeEvents();
62
65
 
63
66
  segments.push({
64
67
  xml: modifyStyling(xml),
65
68
  times: times || [0],
66
69
  previousSubtitleIndex: null,
67
- number: segmentNumber
70
+ number: segmentNumber,
68
71
  });
69
72
 
70
73
  if (segments.length > SEGMENTS_TO_KEEP) {
71
74
  pruneSegments();
72
75
  }
73
- } catch (e) {
74
- DebugTool.info('Error transforming subtitles: ' + e);
76
+ } catch (error) {
77
+ DebugTool.info(`Error transforming subtitles: ${error}`);
75
78
  Plugins.interface.onSubtitlesTransformError();
76
79
  stop();
77
80
  }
78
81
  },
79
82
  onError: ({ statusCode, ...rest } = {}) => {
80
- DebugTool.info('Error loading subtitles data: ' + statusCode);
83
+ DebugTool.info(`Error loading subtitles data: ${statusCode}`);
81
84
  loadErrorFailover({ statusCode, ...rest });
82
85
  },
83
86
  onTimeout: () => {
84
- DebugTool.info('Request timeout loading subtitles');
87
+ DebugTool.info("Request timeout loading subtitles");
85
88
  Plugins.interface.onSubtitlesTimeout({ cdn: mediaSources.currentSubtitlesCdn() });
86
89
  stop();
87
- }
90
+ },
88
91
  });
89
92
  }
90
93
 
91
- function resetLoadErrorCount () {
94
+ function resetLoadErrorCount() {
92
95
  loadErrorCount = 0;
93
96
  }
94
97
 
95
- function loadErrorLimit () {
98
+ function loadErrorLimit() {
96
99
  loadErrorCount++;
97
100
  if (loadErrorCount >= LOAD_ERROR_COUNT_MAX) {
98
101
  resetLoadErrorCount();
@@ -100,8 +103,10 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
100
103
  }
101
104
  }
102
105
 
103
- function loadErrorFailover (opts) {
104
- const errorCase = () => { DebugTool.info('No more CDNs available for subtitle failover'); };
106
+ function loadErrorFailover(opts) {
107
+ const errorCase = () => {
108
+ DebugTool.info("No more CDNs available for subtitle failover");
109
+ };
105
110
 
106
111
  if ((liveSubtitles && loadErrorLimit()) || !liveSubtitles) {
107
112
  stop();
@@ -110,11 +115,11 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
110
115
  }
111
116
  }
112
117
 
113
- function pruneSegments () {
118
+ function pruneSegments() {
114
119
  // Before sorting, check if we've gone back in time, so we know whether to prune from front or back of array
115
120
  const seekedBack = segments[SEGMENTS_TO_KEEP].number < segments[SEGMENTS_TO_KEEP - 1].number;
116
121
 
117
- segments.sort((a, b) => a.number - b.number);
122
+ segments.sort((someSegment, otherSegment) => someSegment.number - otherSegment.number);
118
123
 
119
124
  if (seekedBack) {
120
125
  segments.pop();
@@ -124,7 +129,7 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
124
129
  }
125
130
 
126
131
  // Opts: { backgroundColour: string (css colour, hex), fontFamily: string , size: number, lineHeight: number }
127
- function transformStyleOptions (opts) {
132
+ function transformStyleOptions(opts) {
128
133
  if (opts === undefined) return
129
134
 
130
135
  const customStyles = {};
@@ -137,7 +142,7 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
137
142
  customStyles.fontFamily = opts.fontFamily;
138
143
  }
139
144
 
140
- if (opts.size) {
145
+ if (opts.size > 0) {
141
146
  customStyles.sizeAdjust = opts.size;
142
147
  }
143
148
 
@@ -148,21 +153,25 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
148
153
  return customStyles
149
154
  }
150
155
 
151
- function removeCurrentSubtitlesElement () {
156
+ function isCurrentTimeBehindCurrentSubtitles(currentTime, segments, segmentIndex) {
157
+ return currentTime < segments[segmentIndex].times[currentSegmentRendered.previousSubtitleIndex]
158
+ }
159
+
160
+ function removeCurrentSubtitlesElement() {
152
161
  if (currentSubtitlesElement) {
153
162
  DOMHelpers.safeRemoveElement(currentSubtitlesElement);
154
163
  currentSubtitlesElement = undefined;
155
164
  }
156
165
  }
157
166
 
158
- function removeExampleSubtitlesElement () {
167
+ function removeExampleSubtitlesElement() {
159
168
  if (exampleSubtitlesElement) {
160
169
  DOMHelpers.safeRemoveElement(exampleSubtitlesElement);
161
170
  exampleSubtitlesElement = undefined;
162
171
  }
163
172
  }
164
173
 
165
- function update (currentTime) {
174
+ function update(currentTime) {
166
175
  const segment = getSegmentToRender(currentTime);
167
176
 
168
177
  if (segment) {
@@ -170,17 +179,26 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
170
179
  }
171
180
  }
172
181
 
173
- function getSegmentToRender (currentTime) {
182
+ function getSegmentToRender(currentTime) {
174
183
  let segment;
175
184
 
176
- for (let i = 0; i < segments.length; i++) {
177
- for (let j = 0; j < segments[i].times.length; j++) {
178
- const lastOne = segments[i].times.length === j + 1;
185
+ for (let segmentIndex = 0; segmentIndex < segments.length; segmentIndex++) {
186
+ if (isCurrentTimeBehindCurrentSubtitles(currentTime, segments, segmentIndex)) {
187
+ removeCurrentSubtitlesElement();
188
+ }
179
189
 
180
- if (currentTime >= segments[i].times[j] && (lastOne || currentTime < segments[i].times[j + 1]) && segments[i].previousSubtitleIndex !== j && segments[i].times[j] !== 0) {
181
- segment = segments[i];
182
- currentSegmentRendered = segments[i];
183
- segments[i].previousSubtitleIndex = j;
190
+ for (let timesIndex = 0; timesIndex < segments[segmentIndex].times.length; timesIndex++) {
191
+ const lastOne = segments[segmentIndex].times.length === timesIndex + 1;
192
+
193
+ if (
194
+ currentTime >= segments[segmentIndex].times[timesIndex] &&
195
+ (lastOne || currentTime < segments[segmentIndex].times[timesIndex + 1]) &&
196
+ segments[segmentIndex].previousSubtitleIndex !== timesIndex &&
197
+ segments[segmentIndex].times[timesIndex] !== 0
198
+ ) {
199
+ segment = segments[segmentIndex];
200
+ currentSegmentRendered = segments[segmentIndex];
201
+ segments[segmentIndex].previousSubtitleIndex = timesIndex;
184
202
  break
185
203
  }
186
204
  }
@@ -189,28 +207,34 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
189
207
  return segment
190
208
  }
191
209
 
192
- function render (currentTime, xml) {
210
+ function render(currentTime, xml) {
193
211
  removeCurrentSubtitlesElement();
194
212
 
195
- currentSubtitlesElement = document.createElement('div');
196
- currentSubtitlesElement.id = 'bsp_subtitles';
197
- currentSubtitlesElement.style.position = 'absolute';
213
+ currentSubtitlesElement = document.createElement("div");
214
+ currentSubtitlesElement.id = "bsp_subtitles";
215
+ currentSubtitlesElement.style.position = "absolute";
198
216
  parentElement.appendChild(currentSubtitlesElement);
199
217
 
200
- renderSubtitle(xml, currentTime, currentSubtitlesElement, imscRenderOpts, parentElement.clientHeight, parentElement.clientWidth);
218
+ renderSubtitle(
219
+ xml,
220
+ currentTime,
221
+ currentSubtitlesElement,
222
+ imscRenderOpts,
223
+ parentElement.clientHeight,
224
+ parentElement.clientWidth
225
+ );
201
226
  }
202
227
 
203
- function renderExample (exampleXmlString, styleOpts, safePosition) {
204
- safePosition = safePosition || {};
228
+ function renderExample(exampleXmlString, styleOpts, safePosition = {}) {
205
229
  const exampleXml = fromXML(exampleXmlString);
206
230
  removeExampleSubtitlesElement();
207
231
 
208
232
  const customStyleOptions = transformStyleOptions(styleOpts);
209
233
  const exampleStyle = Utils.merge(imscRenderOpts, customStyleOptions);
210
234
 
211
- exampleSubtitlesElement = document.createElement('div');
212
- exampleSubtitlesElement.id = 'subtitlesPreview';
213
- exampleSubtitlesElement.style.position = 'absolute';
235
+ exampleSubtitlesElement = document.createElement("div");
236
+ exampleSubtitlesElement.id = "subtitlesPreview";
237
+ exampleSubtitlesElement.style.position = "absolute";
214
238
 
215
239
  const elementWidth = parentElement.clientWidth;
216
240
  const elementHeight = parentElement.clientHeight;
@@ -222,48 +246,48 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
222
246
  const renderWidth = elementWidth - leftPixels - rightPixels;
223
247
  const renderHeight = elementHeight - topPixels - bottomPixels;
224
248
 
225
- exampleSubtitlesElement.style.top = (topPixels) + 'px';
226
- exampleSubtitlesElement.style.right = (rightPixels) + 'px';
227
- exampleSubtitlesElement.style.bottom = (bottomPixels) + 'px';
228
- exampleSubtitlesElement.style.left = (leftPixels) + 'px';
249
+ exampleSubtitlesElement.style.top = `${topPixels}px`;
250
+ exampleSubtitlesElement.style.right = `${rightPixels}px`;
251
+ exampleSubtitlesElement.style.bottom = `${bottomPixels}px`;
252
+ exampleSubtitlesElement.style.left = `${leftPixels}px`;
229
253
  parentElement.appendChild(exampleSubtitlesElement);
230
254
 
231
255
  renderSubtitle(exampleXml, 1, exampleSubtitlesElement, exampleStyle, renderHeight, renderWidth);
232
256
  }
233
257
 
234
- function renderSubtitle (xml, currentTime, subsElement, styleOpts, renderHeight, renderWidth) {
258
+ function renderSubtitle(xml, currentTime, subsElement, styleOpts, renderHeight, renderWidth) {
235
259
  try {
236
260
  const isd = generateISD(xml, currentTime);
237
261
  renderHTML(isd, subsElement, null, renderHeight, renderWidth, false, null, null, false, styleOpts);
238
- } catch (e) {
239
- DebugTool.info('Exception while rendering subtitles: ' + e);
262
+ } catch (error) {
263
+ DebugTool.info(`Exception while rendering subtitles: ${error}`);
240
264
  Plugins.interface.onSubtitlesRenderError();
241
265
  }
242
266
  }
243
267
 
244
- function modifyStyling (xml) {
268
+ function modifyStyling(xml) {
245
269
  if (liveSubtitles && xml && xml.head && xml.head.styling) {
246
270
  xml.head.styling.initials = defaultStyleOpts.initials;
247
271
  }
248
272
  return xml
249
273
  }
250
274
 
251
- function timeIsValid (time) {
275
+ function timeIsValid(time) {
252
276
  return time > windowStartEpochSeconds
253
277
  }
254
278
 
255
- function getCurrentTime () {
279
+ function getCurrentTime() {
256
280
  return liveSubtitles ? windowStartEpochSeconds + mediaPlayer.getCurrentTime() : mediaPlayer.getCurrentTime()
257
281
  }
258
282
 
259
- function getWindowStartTime () {
283
+ function getWindowStartTime() {
260
284
  return mediaSources && mediaSources.time().windowStartTime
261
285
  }
262
286
 
263
- function start () {
287
+ function start() {
264
288
  stop();
265
289
  const url = mediaSources.currentSubtitlesSource();
266
- if (url && url !== '') {
290
+ if (url && url !== "") {
267
291
  if (!liveSubtitles && segments.length === 0) {
268
292
  loadSegment(url);
269
293
  }
@@ -278,12 +302,12 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
278
302
  }
279
303
  }
280
304
 
281
- function stop () {
305
+ function stop() {
282
306
  clearInterval(updateInterval);
283
307
  removeCurrentSubtitlesElement();
284
308
  }
285
309
 
286
- function customise (styleOpts, enabled) {
310
+ function customise(styleOpts, enabled) {
287
311
  const customStyleOptions = transformStyleOptions(styleOpts);
288
312
  imscRenderOpts = Utils.merge(imscRenderOpts, customStyleOptions);
289
313
  if (enabled) {
@@ -292,17 +316,17 @@ function IMSCSubtitles (mediaPlayer, autoStart, parentElement, mediaSources, def
292
316
  }
293
317
 
294
318
  return {
295
- start: start,
296
- stop: stop,
319
+ start,
320
+ stop,
297
321
  updatePosition: () => {},
298
- customise: customise,
299
- renderExample: renderExample,
322
+ customise,
323
+ renderExample,
300
324
  clearExample: removeExampleSubtitlesElement,
301
325
  tearDown: () => {
302
326
  stop();
303
327
  resetLoadErrorCount();
304
328
  segments = undefined;
305
- }
329
+ },
306
330
  }
307
331
  }
308
332
 
@@ -1,4 +1,4 @@
1
- import { D as DOMHelpers, a as DebugTool, P as Plugins, L as LoadUrl, T as TransportControlPosition } from './main-61b49de6.js';
1
+ import { D as DOMHelpers, a as DebugTool, P as Plugins, L as LoadUrl, T as TransportControlPosition } from './main-ba52ef8f.js';
2
2
 
3
3
  /**
4
4
  * Safely checks if an attribute exists on an element.
@@ -5732,12 +5732,12 @@ function StrategyPicker (windowType, isUHD) {
5732
5732
  return resolve(NativeStrategy)
5733
5733
  }
5734
5734
 
5735
- return import('./msestrategy-112ba6b7.js').then(({ default: MSEStrategy }) => resolve(MSEStrategy))
5735
+ return import('./msestrategy-8219ff78.js').then(({ default: MSEStrategy }) => resolve(MSEStrategy))
5736
5736
  .catch(() => {
5737
5737
  reject({ error: 'strategyDynamicLoadError' });
5738
5738
  })
5739
5739
  } else if (window.bigscreenPlayer.playbackStrategy === PlaybackStrategy.MSE) {
5740
- return import('./msestrategy-112ba6b7.js').then(({ default: MSEStrategy }) => resolve(MSEStrategy))
5740
+ return import('./msestrategy-8219ff78.js').then(({ default: MSEStrategy }) => resolve(MSEStrategy))
5741
5741
  .catch(() => {
5742
5742
  reject({ error: 'strategyDynamicLoadError' });
5743
5743
  })
@@ -6141,7 +6141,7 @@ function CallCallbacks (callbacks, data) {
6141
6141
  }
6142
6142
  }
6143
6143
 
6144
- var version = "5.6.2";
6144
+ var version = "5.6.5";
6145
6145
 
6146
6146
  var sourceList;
6147
6147
  var source;
@@ -7341,14 +7341,14 @@ function Subtitles (mediaPlayer, autoStart, playbackElement, defaultStyleOpts, m
7341
7341
  let subtitlesContainer;
7342
7342
 
7343
7343
  if (useLegacySubs) {
7344
- import('./legacysubtitles-48008e22.js').then(({ default: LegacySubtitles }) => {
7344
+ import('./legacysubtitles-42fed2a6.js').then(({ default: LegacySubtitles }) => {
7345
7345
  subtitlesContainer = LegacySubtitles(mediaPlayer, autoStart, playbackElement, mediaSources, defaultStyleOpts);
7346
7346
  callback(subtitlesEnabled);
7347
7347
  }).catch(() => {
7348
7348
  Plugins.interface.onSubtitlesDynamicLoadError();
7349
7349
  });
7350
7350
  } else {
7351
- import('./imscsubtitles-1012091b.js').then(({ default: IMSCSubtitles }) => {
7351
+ import('./imscsubtitles-ed9d9bd6.js').then(({ default: IMSCSubtitles }) => {
7352
7352
  subtitlesContainer = IMSCSubtitles(mediaPlayer, autoStart, playbackElement, mediaSources, defaultStyleOpts);
7353
7353
  callback(subtitlesEnabled);
7354
7354
  }).catch(() => {
package/dist/esm/main.js CHANGED
@@ -1 +1 @@
1
- export { B as BigscreenPlayer, c as LiveSupport, d as MediaKinds, M as MediaState, f as MockBigscreenPlayer, g as PauseTriggers, h as PlaybackStrategy, i as TransferFormat, T as TransportControlPosition, W as WindowTypes } from './main-61b49de6.js';
1
+ export { B as BigscreenPlayer, c as LiveSupport, d as MediaKinds, M as MediaState, f as MockBigscreenPlayer, g as PauseTriggers, h as PlaybackStrategy, i as TransferFormat, T as TransportControlPosition, W as WindowTypes } from './main-ba52ef8f.js';
@@ -1,4 +1,4 @@
1
- import { U as Utils, D as DOMHelpers, W as WindowTypes, c as LiveSupport, M as MediaState, a as DebugTool, P as Plugins, d as MediaKinds, b as TimeUtils, e as DynamicWindowUtils } from './main-61b49de6.js';
1
+ import { U as Utils, D as DOMHelpers, W as WindowTypes, c as LiveSupport, M as MediaState, a as DebugTool, P as Plugins, d as MediaKinds, b as TimeUtils, e as DynamicWindowUtils } from './main-ba52ef8f.js';
2
2
  import { MediaPlayer } from 'dashjs/index_mediaplayerOnly';
3
3
 
4
4
  function filter (manifest, representationOptions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bigscreen-player",
3
- "version": "5.6.2",
3
+ "version": "5.6.5",
4
4
  "description": "Simplified media playback for bigscreen devices.",
5
5
  "main": "dist/esm/main.js",
6
6
  "browser": "dist/esm/main.js",
@@ -16,15 +16,18 @@
16
16
  "scripts": {
17
17
  "prepare": "[ ! -d dist/ ] && npm run build || exit 0",
18
18
  "docs": "npx jsdoc -c jsdoc.conf.json",
19
- "build": "rollup -c rollup.config.js",
19
+ "build": "npm run build:clean && npm run build:bundle",
20
+ "build:clean": "rm -rf dist",
21
+ "build:bundle": "rollup -c rollup.config.js",
20
22
  "watch": "rollup -c rollup.config.js -w",
21
23
  "start": "rollup -c rollup.dev.config.js -w",
22
24
  "test": "jest",
23
25
  "coverage": "jest --coverage",
24
- "lint": "npx eslint ."
26
+ "lint": "eslint ."
25
27
  },
26
28
  "husky": {
27
29
  "hooks": {
30
+ "pre-commit": "./scripts/lint-staged.sh && ./scripts/format-staged.sh",
28
31
  "pre-push": "npm test"
29
32
  }
30
33
  },
@@ -40,15 +43,16 @@
40
43
  "@rollup/plugin-node-resolve": "^13.0.4",
41
44
  "babel-jest": "^27.0.6",
42
45
  "clean-jsdoc-theme": "^3.2.7",
43
- "eslint": "^7.2.0",
44
- "eslint-plugin-es5": "1.3.1",
45
- "eslint-plugin-jest": "^24.4.0",
46
- "eslint-plugin-node": "^7.0.1",
47
- "eslint-plugin-promise": "4.0.1",
48
- "eslint-plugin-standard": "4.0.0",
46
+ "eslint": "^8.27.0",
47
+ "eslint-plugin-import": "^2.26.0",
48
+ "eslint-plugin-jest": "^27.1.4",
49
+ "eslint-plugin-json": "^3.1.0",
50
+ "eslint-plugin-sonarjs": "^0.16.0",
51
+ "eslint-plugin-unicorn": "^44.0.2",
49
52
  "husky": "^4.2.5",
50
53
  "jest": "^27.0.6",
51
54
  "jsdoc": "^3.6.4",
55
+ "prettier": "^2.7.1",
52
56
  "rollup": "^2.54.0",
53
57
  "rollup-plugin-livereload": "^2.0.5",
54
58
  "rollup-plugin-polyfill-node": "^0.7.0",