shaka-player 3.2.16 → 3.2.18
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/.github/workflows/build-and-test.yaml +13 -0
- package/AUTHORS +1 -0
- package/CHANGELOG.md +20 -0
- package/CONTRIBUTORS +1 -0
- package/dist/locales.js +29 -29
- package/dist/shaka-player.compiled.debug.js +72 -71
- package/dist/shaka-player.compiled.debug.map +3 -3
- package/dist/shaka-player.compiled.js +229 -229
- package/dist/shaka-player.compiled.map +2 -2
- package/dist/shaka-player.ui.debug.js +86 -85
- package/dist/shaka-player.ui.debug.map +3 -3
- package/dist/shaka-player.ui.js +236 -235
- package/dist/shaka-player.ui.map +3 -3
- package/lib/ads/ad_manager.js +2 -2
- package/lib/media/streaming_engine.js +20 -8
- package/lib/player.js +17 -2
- package/lib/text/ui_text_displayer.js +24 -4
- package/lib/text/web_vtt_generator.js +21 -9
- package/lib/util/dom_utils.js +3 -1
- package/lib/util/stream_utils.js +6 -0
- package/package.json +1 -1
- package/test/player_integration.js +10 -3
- package/test/player_unit.js +4 -2
- package/test/test/boot.js +29 -11
- package/test/test/util/test_scheme.js +2 -2
- package/test/text/ui_text_displayer_unit.js +70 -0
package/lib/ads/ad_manager.js
CHANGED
|
@@ -19,8 +19,8 @@ goog.require('shaka.util.IReleasable');
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* @event shaka.ads.AdManager.
|
|
23
|
-
* @description Fired when
|
|
22
|
+
* @event shaka.ads.AdManager.AdsLoadedEvent
|
|
23
|
+
* @description Fired when a sequence of ads has been loaded.
|
|
24
24
|
* @property {string} type
|
|
25
25
|
* 'ads-loaded'
|
|
26
26
|
* @property {number} loadTime
|
|
@@ -598,6 +598,11 @@ shaka.media.StreamingEngine = class {
|
|
|
598
598
|
* within the presentation timeline.
|
|
599
599
|
*/
|
|
600
600
|
seeked() {
|
|
601
|
+
if (!this.playerInterface_) {
|
|
602
|
+
// Already destroyed.
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
|
|
601
606
|
const presentationTime = this.playerInterface_.getPresentationTime();
|
|
602
607
|
const smallGapLimit = this.config_.smallGapLimit;
|
|
603
608
|
const ContentType = shaka.util.ManifestParserUtils.ContentType;
|
|
@@ -652,7 +657,7 @@ shaka.media.StreamingEngine = class {
|
|
|
652
657
|
|
|
653
658
|
/**
|
|
654
659
|
* Clear the buffer for a given stream. Unlike clearBuffer_, this will handle
|
|
655
|
-
* cases where a MediaState is performing an update. After this runs,
|
|
660
|
+
* cases where a MediaState is performing an update. After this runs, the
|
|
656
661
|
* MediaState will have a pending update.
|
|
657
662
|
* @param {!shaka.media.StreamingEngine.MediaState_} mediaState
|
|
658
663
|
* @private
|
|
@@ -767,9 +772,9 @@ shaka.media.StreamingEngine = class {
|
|
|
767
772
|
for (const type of streamsByType.keys()) {
|
|
768
773
|
const stream = streamsByType.get(type);
|
|
769
774
|
if (!this.mediaStates_.has(type)) {
|
|
770
|
-
const
|
|
771
|
-
this.mediaStates_.set(type,
|
|
772
|
-
this.scheduleUpdate_(
|
|
775
|
+
const mediaState = this.createMediaState_(stream);
|
|
776
|
+
this.mediaStates_.set(type, mediaState);
|
|
777
|
+
this.scheduleUpdate_(mediaState, 0);
|
|
773
778
|
}
|
|
774
779
|
}
|
|
775
780
|
}
|
|
@@ -873,7 +878,7 @@ shaka.media.StreamingEngine = class {
|
|
|
873
878
|
// We switched streams while in the middle of this async call to
|
|
874
879
|
// createSegmentIndex. Abandon this update and schedule a new one if
|
|
875
880
|
// there's not already one pending.
|
|
876
|
-
if (mediaState.
|
|
881
|
+
if (!mediaState.performingUpdate && !mediaState.updateTimer) {
|
|
877
882
|
this.scheduleUpdate_(mediaState, 0);
|
|
878
883
|
}
|
|
879
884
|
return;
|
|
@@ -1341,7 +1346,7 @@ shaka.media.StreamingEngine = class {
|
|
|
1341
1346
|
// If the network slows down, abort the current fetch request and start
|
|
1342
1347
|
// a new one, and ignore the error message.
|
|
1343
1348
|
mediaState.performingUpdate = false;
|
|
1344
|
-
mediaState
|
|
1349
|
+
this.cancelUpdate_(mediaState);
|
|
1345
1350
|
this.scheduleUpdate_(mediaState, 0);
|
|
1346
1351
|
} else if (mediaState.type == ContentType.TEXT &&
|
|
1347
1352
|
this.config_.ignoreTextStreamFailures) {
|
|
@@ -1386,7 +1391,10 @@ shaka.media.StreamingEngine = class {
|
|
|
1386
1391
|
|
|
1387
1392
|
for (const mediaState of this.mediaStates_.values()) {
|
|
1388
1393
|
const logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState);
|
|
1389
|
-
if
|
|
1394
|
+
// Only schedule an update if it has an error, but it's not mid-update
|
|
1395
|
+
// and there is not already an update scheduled.
|
|
1396
|
+
if (mediaState.hasError && !mediaState.performingUpdate &&
|
|
1397
|
+
!mediaState.updateTimer) {
|
|
1390
1398
|
shaka.log.info(logPrefix, 'Retrying after failure...');
|
|
1391
1399
|
mediaState.hasError = false;
|
|
1392
1400
|
this.scheduleUpdate_(mediaState, delaySeconds);
|
|
@@ -1851,7 +1859,11 @@ shaka.media.StreamingEngine = class {
|
|
|
1851
1859
|
shaka.log.debug(logPrefix, 'cleared buffer');
|
|
1852
1860
|
mediaState.clearingBuffer = false;
|
|
1853
1861
|
mediaState.endOfStream = false;
|
|
1854
|
-
|
|
1862
|
+
// Since the clear operation was async, check to make sure we're not doing
|
|
1863
|
+
// another update and we don't have one scheduled yet.
|
|
1864
|
+
if (!mediaState.performingUpdate && !mediaState.updateTimer) {
|
|
1865
|
+
this.scheduleUpdate_(mediaState, 0);
|
|
1866
|
+
}
|
|
1855
1867
|
}
|
|
1856
1868
|
|
|
1857
1869
|
|
package/lib/player.js
CHANGED
|
@@ -1342,6 +1342,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
1342
1342
|
has.startTime = null;
|
|
1343
1343
|
has.uri = null;
|
|
1344
1344
|
|
|
1345
|
+
// Release the region timeline, which is created when parsing the manifest.
|
|
1346
|
+
if (this.regionTimeline_) {
|
|
1347
|
+
this.regionTimeline_.release();
|
|
1348
|
+
this.regionTimeline_ = null;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1345
1351
|
// In most cases we should have a media element. The one exception would
|
|
1346
1352
|
// be if there was an error and we, by chance, did not have a media element.
|
|
1347
1353
|
if (has.mediaElement) {
|
|
@@ -3952,16 +3958,25 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
3952
3958
|
return [];
|
|
3953
3959
|
}
|
|
3954
3960
|
const chapters = [];
|
|
3961
|
+
const uniqueChapters = new Set();
|
|
3955
3962
|
for (const chaptersTrack of chaptersTracksWithLanguage) {
|
|
3956
3963
|
if (chaptersTrack && chaptersTrack.cues) {
|
|
3957
3964
|
for (const cue of chaptersTrack.cues) {
|
|
3965
|
+
let id = cue.id;
|
|
3966
|
+
if (!id || id == '') {
|
|
3967
|
+
id = cue.startTime + '-' + cue.endTime + '-' + cue.text;
|
|
3968
|
+
}
|
|
3958
3969
|
/** @type {shaka.extern.Chapter} */
|
|
3959
3970
|
const chapter = {
|
|
3971
|
+
id: id,
|
|
3960
3972
|
title: cue.text,
|
|
3961
3973
|
startTime: cue.startTime,
|
|
3962
3974
|
endTime: cue.endTime,
|
|
3963
3975
|
};
|
|
3964
|
-
|
|
3976
|
+
if (!uniqueChapters.has(id)) {
|
|
3977
|
+
chapters.push(chapter);
|
|
3978
|
+
uniqueChapters.add(id);
|
|
3979
|
+
}
|
|
3965
3980
|
}
|
|
3966
3981
|
}
|
|
3967
3982
|
}
|
|
@@ -6444,7 +6459,7 @@ shaka.Player.TYPICAL_BUFFERING_THRESHOLD_ = 0.5;
|
|
|
6444
6459
|
* @define {string} A version number taken from git at compile time.
|
|
6445
6460
|
* @export
|
|
6446
6461
|
*/
|
|
6447
|
-
shaka.Player.version = 'v3.2.
|
|
6462
|
+
shaka.Player.version = 'v3.2.18-uncompiled';
|
|
6448
6463
|
|
|
6449
6464
|
// Initialize the deprecation system using the version string we just set
|
|
6450
6465
|
// on the player.
|
|
@@ -372,6 +372,25 @@ shaka.text.UITextDisplayer = class {
|
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Compute a unique internal id:
|
|
377
|
+
* Regions can reuse the id but have different dimensions, we need to
|
|
378
|
+
* consider those differences
|
|
379
|
+
* @param {shaka.extern.CueRegion} region
|
|
380
|
+
* @private
|
|
381
|
+
*/
|
|
382
|
+
generateRegionId_(region) {
|
|
383
|
+
const percentageUnit = shaka.text.CueRegion.units.PERCENTAGE;
|
|
384
|
+
const heightUnit = region.heightUnits == percentageUnit ? '%' : 'px';
|
|
385
|
+
const viewportAnchorUnit =
|
|
386
|
+
region.viewportAnchorUnits == percentageUnit ? '%' : 'px';
|
|
387
|
+
const uniqueRegionId = `${region.id}_${
|
|
388
|
+
region.width}x${region.height}${heightUnit}-${
|
|
389
|
+
region.viewportAnchorX}x${region.viewportAnchorY}${viewportAnchorUnit}`;
|
|
390
|
+
|
|
391
|
+
return uniqueRegionId;
|
|
392
|
+
}
|
|
393
|
+
|
|
375
394
|
/**
|
|
376
395
|
* Get or create a region element corresponding to the cue region. These are
|
|
377
396
|
* cached by ID.
|
|
@@ -383,8 +402,9 @@ shaka.text.UITextDisplayer = class {
|
|
|
383
402
|
getRegionElement_(cue) {
|
|
384
403
|
const region = cue.region;
|
|
385
404
|
|
|
386
|
-
|
|
387
|
-
|
|
405
|
+
const regionId = this.generateRegionId_(region);
|
|
406
|
+
if (this.regionElements_.has(regionId)) {
|
|
407
|
+
return this.regionElements_.get(regionId);
|
|
388
408
|
}
|
|
389
409
|
|
|
390
410
|
const regionElement = shaka.util.Dom.createHTMLElement('span');
|
|
@@ -395,7 +415,7 @@ shaka.text.UITextDisplayer = class {
|
|
|
395
415
|
const viewportAnchorUnit =
|
|
396
416
|
region.viewportAnchorUnits == percentageUnit ? '%' : 'px';
|
|
397
417
|
|
|
398
|
-
regionElement.id = 'shaka-text-region---' +
|
|
418
|
+
regionElement.id = 'shaka-text-region---' + regionId;
|
|
399
419
|
regionElement.classList.add('shaka-text-region');
|
|
400
420
|
|
|
401
421
|
regionElement.style.height = region.height + heightUnit;
|
|
@@ -416,7 +436,7 @@ shaka.text.UITextDisplayer = class {
|
|
|
416
436
|
regionElement.style.justifyContent = 'flex-end';
|
|
417
437
|
}
|
|
418
438
|
|
|
419
|
-
this.regionElements_.set(
|
|
439
|
+
this.regionElements_.set(regionId, regionElement);
|
|
420
440
|
return regionElement;
|
|
421
441
|
}
|
|
422
442
|
|
|
@@ -87,16 +87,28 @@ shaka.text.WebVttGenerator = class {
|
|
|
87
87
|
// We don't want to modify the array or objects passed in, since we don't
|
|
88
88
|
// technically own them. So we build a new array and replace certain items
|
|
89
89
|
// in it if they need to be flattened.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
// We also don't want to flatten the text payloads starting at a container
|
|
91
|
+
// element; otherwise, for containers encapsulating multiple caption lines,
|
|
92
|
+
// the lines would merge into a single cue. This is undesirable when a
|
|
93
|
+
// subset of the captions are outside of the append time window. To fix
|
|
94
|
+
// this, we only call flattenPayload() starting at elements marked as
|
|
95
|
+
// isContainer = false.
|
|
96
|
+
const getCuesToFlatten = (cues, result) => {
|
|
97
|
+
for (const cue of cues) {
|
|
98
|
+
if (cue.isContainer) {
|
|
99
|
+
// Recurse to find the actual text payload cues.
|
|
100
|
+
getCuesToFlatten(cue.nestedCues, result);
|
|
101
|
+
} else {
|
|
102
|
+
// Flatten the payload.
|
|
103
|
+
const flatCue = cue.clone();
|
|
104
|
+
flatCue.nestedCues = [];
|
|
105
|
+
flatCue.payload = flattenPayload(cue);
|
|
106
|
+
result.push(flatCue);
|
|
107
|
+
}
|
|
98
108
|
}
|
|
99
|
-
|
|
109
|
+
return result;
|
|
110
|
+
};
|
|
111
|
+
const flattenedCues = getCuesToFlatten(cues, []);
|
|
100
112
|
|
|
101
113
|
let webvttString = 'WEBVTT\n\n';
|
|
102
114
|
for (const cue of flattenedCues) {
|
package/lib/util/dom_utils.js
CHANGED
|
@@ -36,7 +36,9 @@ shaka.util.Dom = class {
|
|
|
36
36
|
* @return {!HTMLButtonElement}
|
|
37
37
|
*/
|
|
38
38
|
static createButton() {
|
|
39
|
-
|
|
39
|
+
const button = document.createElement('button');
|
|
40
|
+
button.setAttribute('type', 'button');
|
|
41
|
+
return /** @type {!HTMLButtonElement} */ (button);
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
|
package/lib/util/stream_utils.js
CHANGED
|
@@ -450,12 +450,16 @@ shaka.util.StreamUtils = class {
|
|
|
450
450
|
if (!MediaSource.isTypeSupported(audioFullType)) {
|
|
451
451
|
return false;
|
|
452
452
|
}
|
|
453
|
+
// Update the codec string with the (possibly) converted codecs.
|
|
454
|
+
videoCodecs = [videoCodecs, audioCodecs].join(',');
|
|
453
455
|
}
|
|
454
456
|
const fullType = shaka.util.MimeUtils.getFullOrConvertedType(
|
|
455
457
|
video.mimeType, videoCodecs, ContentType.VIDEO);
|
|
456
458
|
if (!MediaSource.isTypeSupported(fullType)) {
|
|
457
459
|
return false;
|
|
458
460
|
}
|
|
461
|
+
// Update the codec string with the (possibly) converted codecs.
|
|
462
|
+
video.codecs = videoCodecs;
|
|
459
463
|
}
|
|
460
464
|
const audio = variant.audio;
|
|
461
465
|
if (audio) {
|
|
@@ -466,6 +470,8 @@ shaka.util.StreamUtils = class {
|
|
|
466
470
|
if (!MediaSource.isTypeSupported(fullType)) {
|
|
467
471
|
return false;
|
|
468
472
|
}
|
|
473
|
+
// Update the codec string with the (possibly) converted codecs.
|
|
474
|
+
audio.codecs = codecs;
|
|
469
475
|
}
|
|
470
476
|
|
|
471
477
|
// See: https://github.com/shaka-project/shaka-player/issues/3380
|
package/package.json
CHANGED
|
@@ -779,7 +779,7 @@ describe('Player', () => {
|
|
|
779
779
|
expect(getBufferedBehind()).toBe(20); // Buffered to start still.
|
|
780
780
|
video.currentTime = 50;
|
|
781
781
|
await waitUntilBuffered(30);
|
|
782
|
-
expect(getBufferedBehind()).toBeLessThan(
|
|
782
|
+
expect(getBufferedBehind()).toBeLessThan(40); // 30 + segment_size
|
|
783
783
|
|
|
784
784
|
player.configure('streaming.bufferBehind', 10);
|
|
785
785
|
// We only evict content when we append a segment, so increase the
|
|
@@ -806,7 +806,7 @@ describe('Player', () => {
|
|
|
806
806
|
}
|
|
807
807
|
|
|
808
808
|
async function waitUntilBuffered(amount) {
|
|
809
|
-
for (let i = 0; i <
|
|
809
|
+
for (let i = 0; i < 50; i++) {
|
|
810
810
|
// We buffer from an internal segment, so this shouldn't take long to
|
|
811
811
|
// buffer.
|
|
812
812
|
await Util.delay(0.1); // eslint-disable-line no-await-in-loop
|
|
@@ -814,7 +814,14 @@ describe('Player', () => {
|
|
|
814
814
|
return;
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
|
-
|
|
817
|
+
|
|
818
|
+
const ranges =
|
|
819
|
+
shaka.media.TimeRangesUtils.getBufferedInfo(video.buffered);
|
|
820
|
+
const currentTime = video.currentTime;
|
|
821
|
+
const target = currentTime + amount;
|
|
822
|
+
|
|
823
|
+
throw new Error('Timeout waiting to buffer! ' +
|
|
824
|
+
JSON.stringify({ranges, currentTime, target}));
|
|
818
825
|
}
|
|
819
826
|
}); // describe('buffering')
|
|
820
827
|
|
package/test/player_unit.js
CHANGED
|
@@ -3185,7 +3185,9 @@ describe('Player', () => {
|
|
|
3185
3185
|
variant.addAudio(0, (stream) => {
|
|
3186
3186
|
stream.channelsCount = 6;
|
|
3187
3187
|
stream.audioSamplingRate = 48000;
|
|
3188
|
-
|
|
3188
|
+
// ac-3 is rewritten as ec-3 on Tizen, so for the stability of this
|
|
3189
|
+
// test case, use ec-3.
|
|
3190
|
+
stream.codecs = 'ec-3';
|
|
3189
3191
|
});
|
|
3190
3192
|
});
|
|
3191
3193
|
|
|
@@ -3210,7 +3212,7 @@ describe('Player', () => {
|
|
|
3210
3212
|
expect(abrManager.variants.length).toBe(1);
|
|
3211
3213
|
// It should be the 6-channel variant, based on our preference.
|
|
3212
3214
|
expect(abrManager.variants[0].audio.channelsCount).toBe(6);
|
|
3213
|
-
expect(abrManager.variants[0].audio.codecs).toBe('
|
|
3215
|
+
expect(abrManager.variants[0].audio.codecs).toBe('ec-3');
|
|
3214
3216
|
});
|
|
3215
3217
|
});
|
|
3216
3218
|
|
package/test/test/boot.js
CHANGED
|
@@ -66,22 +66,40 @@ function failTestsOnNamespacedElementOrAttributeNames() {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
69
|
+
* Fail the current test on a given error, constructed with a given header and
|
|
70
|
+
* the full stack trace of the error.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} messageHeader
|
|
73
|
+
* @param {!Error} error
|
|
71
74
|
*/
|
|
72
|
-
function
|
|
75
|
+
function failOnError(messageHeader, error) {
|
|
76
|
+
let message = `${messageHeader}: ${error}`;
|
|
77
|
+
// Shaka errors have the stack trace in their toString() already, so don't
|
|
78
|
+
// add it again. For native errors, we need to see where it came from.
|
|
79
|
+
if (error && error.stack && !(error instanceof shaka.util.Error)) {
|
|
80
|
+
message += '\n' + error.stack;
|
|
81
|
+
}
|
|
82
|
+
fail(message);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Listen for unhandled errors and Promise rejections (which may occur after a
|
|
87
|
+
* test) and convert them into test failures.
|
|
88
|
+
*/
|
|
89
|
+
function failTestsOnUnhandledErrors() {
|
|
73
90
|
// https://developer.mozilla.org/en-US/docs/Web/Events/unhandledrejection
|
|
74
91
|
window.addEventListener('unhandledrejection', (event) => {
|
|
75
92
|
/** @type {?} */
|
|
76
93
|
const error = event.reason;
|
|
77
|
-
|
|
94
|
+
failOnError('Unhandled rejection in Promise', error);
|
|
95
|
+
});
|
|
78
96
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Window/error_event
|
|
98
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent
|
|
99
|
+
window.addEventListener('error', (event) => {
|
|
100
|
+
/** @type {?} */
|
|
101
|
+
const error = event['error'];
|
|
102
|
+
failOnError('Unhandled error', error);
|
|
85
103
|
});
|
|
86
104
|
}
|
|
87
105
|
|
|
@@ -387,7 +405,7 @@ function configureJasmineEnvironment() {
|
|
|
387
405
|
function setupTestEnvironment() {
|
|
388
406
|
failTestsOnFailedAssertions();
|
|
389
407
|
failTestsOnNamespacedElementOrAttributeNames();
|
|
390
|
-
|
|
408
|
+
failTestsOnUnhandledErrors();
|
|
391
409
|
disableScrollbars();
|
|
392
410
|
workAroundLegacyEdgePromiseIssues();
|
|
393
411
|
|
|
@@ -389,7 +389,7 @@ const sintelAudioSegment = {
|
|
|
389
389
|
mdhdOffset: 0x1b6,
|
|
390
390
|
segmentUri: '/base/test/test/assets/sintel-audio-segment.mp4',
|
|
391
391
|
tfdtOffset: 0x3c,
|
|
392
|
-
segmentDuration: 10
|
|
392
|
+
segmentDuration: 10,
|
|
393
393
|
mimeType: 'audio/mp4',
|
|
394
394
|
codecs: 'mp4a.40.2',
|
|
395
395
|
};
|
|
@@ -415,7 +415,7 @@ const sintelEncryptedAudio = {
|
|
|
415
415
|
mdhdOffset: 0x1b6,
|
|
416
416
|
segmentUri: '/base/test/test/assets/encrypted-sintel-audio-segment.mp4',
|
|
417
417
|
tfdtOffset: 0x3c,
|
|
418
|
-
segmentDuration: 10
|
|
418
|
+
segmentDuration: 10,
|
|
419
419
|
mimeType: 'audio/mp4',
|
|
420
420
|
codecs: 'mp4a.40.2',
|
|
421
421
|
initData:
|
|
@@ -537,4 +537,74 @@ describe('UITextDisplayer', () => {
|
|
|
537
537
|
'.shaka-text-region');
|
|
538
538
|
expect(allRegionElements.length).toBe(1);
|
|
539
539
|
});
|
|
540
|
+
|
|
541
|
+
it('creates separate regions when dimensions differ but id same', () => {
|
|
542
|
+
const identicalRegionId = 'regionId';
|
|
543
|
+
|
|
544
|
+
const cueRegion1 = new shaka.text.CueRegion();
|
|
545
|
+
const cueRegion2 = new shaka.text.CueRegion();
|
|
546
|
+
cueRegion1.id = identicalRegionId;
|
|
547
|
+
cueRegion2.id = identicalRegionId;
|
|
548
|
+
|
|
549
|
+
cueRegion1.height = 80;
|
|
550
|
+
cueRegion1.heightUnits = shaka.text.CueRegion.units.PERCENTAGE;
|
|
551
|
+
cueRegion1.width = 80;
|
|
552
|
+
cueRegion1.widthUnits = shaka.text.CueRegion.units.PERCENTAGE;
|
|
553
|
+
|
|
554
|
+
cueRegion2.height = 160; // the only difference!
|
|
555
|
+
cueRegion2.heightUnits = shaka.text.CueRegion.units.PERCENTAGE;
|
|
556
|
+
cueRegion2.width = 80;
|
|
557
|
+
cueRegion2.widthUnits = shaka.text.CueRegion.units.PERCENTAGE;
|
|
558
|
+
|
|
559
|
+
cueRegion1.viewportAnchorX = 10;
|
|
560
|
+
cueRegion1.viewportAnchorY = 10;
|
|
561
|
+
cueRegion1.viewportAnchorUnits = shaka.text.CueRegion.units.PERCENTAGE;
|
|
562
|
+
|
|
563
|
+
cueRegion2.viewportAnchorX = 10;
|
|
564
|
+
cueRegion2.viewportAnchorY = 10;
|
|
565
|
+
cueRegion2.viewportAnchorUnits = shaka.text.CueRegion.units.PERCENTAGE;
|
|
566
|
+
|
|
567
|
+
// These all attach to the same region, but only one region element should
|
|
568
|
+
// be created.
|
|
569
|
+
const firstBatchOfCues = [
|
|
570
|
+
new shaka.text.Cue(0, 100, ''),
|
|
571
|
+
new shaka.text.Cue(0, 100, ''),
|
|
572
|
+
new shaka.text.Cue(0, 100, ''),
|
|
573
|
+
];
|
|
574
|
+
for (const cue of firstBatchOfCues) {
|
|
575
|
+
cue.displayAlign = shaka.text.Cue.displayAlign.CENTER;
|
|
576
|
+
cue.region = cueRegion1;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Another batch for the other region
|
|
580
|
+
const secondBatchOfCues = [
|
|
581
|
+
new shaka.text.Cue(0, 100, ''),
|
|
582
|
+
new shaka.text.Cue(0, 100, ''),
|
|
583
|
+
new shaka.text.Cue(0, 100, ''),
|
|
584
|
+
];
|
|
585
|
+
for (const cue of secondBatchOfCues) {
|
|
586
|
+
cue.displayAlign = shaka.text.Cue.displayAlign.CENTER;
|
|
587
|
+
cue.region = cueRegion2;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
textDisplayer.setTextVisibility(true);
|
|
591
|
+
textDisplayer.append(firstBatchOfCues);
|
|
592
|
+
textDisplayer.append(secondBatchOfCues);
|
|
593
|
+
updateCaptions();
|
|
594
|
+
|
|
595
|
+
const textContainer = videoContainer.querySelector('.shaka-text-container');
|
|
596
|
+
const allRegionElements = textContainer.querySelectorAll(
|
|
597
|
+
'.shaka-text-region');
|
|
598
|
+
|
|
599
|
+
// Verify that the nested cues are attached to respective region element.
|
|
600
|
+
expect(allRegionElements.length).toBe(2);
|
|
601
|
+
|
|
602
|
+
const childrenOfOne = Array.from(allRegionElements[0].childNodes).filter(
|
|
603
|
+
(e) => e.nodeType == Node.ELEMENT_NODE);
|
|
604
|
+
expect(childrenOfOne.length).toBe(3);
|
|
605
|
+
|
|
606
|
+
const childrenOfTwo = Array.from(allRegionElements[1].childNodes).filter(
|
|
607
|
+
(e) => e.nodeType == Node.ELEMENT_NODE);
|
|
608
|
+
expect(childrenOfTwo.length).toBe(3);
|
|
609
|
+
});
|
|
540
610
|
});
|