Skip to content

Commit 1e3453e

Browse files
authored
Fix interstitial asset events not firing when attaching primary early for playout-limit change (video-dev#7467)
* Fix interstitial asset events not firing when attaching primary early for playout-limit change * Add log message helper for timeline position updates
1 parent c64313b commit 1e3453e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

docs/API.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,9 @@ This configuration will be applied by default to all instances.
569569

570570
(default: `false`)
571571

572-
Setting `config.debug = true;` will turn on debug logs on JS console.
572+
Setting `config.debug = true` enables JavaScript debug console logs. Debug mode also disables catching exceptions in even handler callbacks.
573+
In debug mode, when an event listener throws, the exception is not caught. This allows uncaught exeptions to trigger the JavaScript debugger.
574+
In production mode (`config.debug = false`), exceptions that are caught in event handlers are redispatched as errors with `type: OTHER_ERROR, details: INTERNAL_EXCEPTION, error: <caught exception>`.
573575

574576
A logger object could also be provided for custom logging: `config.debug = customLogger;`.
575577

src/controller/interstitials-controller.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ function playWithCatch(media: HTMLMediaElement | null) {
8686
});
8787
}
8888

89+
function timelineMessage(label: string, time: number) {
90+
return `[${label}] Advancing timeline position to ${time}`;
91+
}
92+
8993
export default class InterstitialsController
9094
extends Logger
9195
implements NetworkComponentAPI
@@ -281,6 +285,7 @@ export default class InterstitialsController
281285
}
282286

283287
private clearScheduleState() {
288+
this.log(`clear schedule state`);
284289
this.playingItem =
285290
this.bufferingItem =
286291
this.waitingItem =
@@ -308,6 +313,7 @@ export default class InterstitialsController
308313
if (this.detachedData) {
309314
const player = this.getBufferingPlayer();
310315
if (player) {
316+
this.log(`Removing schedule state for detachedData and ${player}`);
311317
this.playingAsset =
312318
this.endedAsset =
313319
this.bufferingAsset =
@@ -1027,6 +1033,7 @@ export default class InterstitialsController
10271033
const effectivePlayingItem = this.effectivePlayingItem;
10281034
if (timelinePos === -1) {
10291035
const startPosition = this.hls.startPosition;
1036+
this.log(timelineMessage('checkStart', startPosition));
10301037
this.timelinePos = startPosition;
10311038
if (interstitialEvents.length && interstitialEvents[0].cue.pre) {
10321039
const index = schedule.findEventIndex(interstitialEvents[0].identifier);
@@ -1090,6 +1097,7 @@ export default class InterstitialsController
10901097
}
10911098
const resumptionTime = interstitial.resumeTime;
10921099
if (this.timelinePos < resumptionTime) {
1100+
this.log(timelineMessage('advanceAfterAssetEnded', resumptionTime));
10931101
this.timelinePos = resumptionTime;
10941102
if (interstitial.appendInPlace) {
10951103
this.advanceInPlace(resumptionTime);
@@ -1125,7 +1133,7 @@ export default class InterstitialsController
11251133
}
11261134
const scheduledItem = index >= 0 ? scheduleItems[index] : null;
11271135
this.log(
1128-
`setSchedulePosition ${index}, ${assetListIndex} (${scheduledItem ? segmentToString(scheduledItem) : scheduledItem})`,
1136+
`setSchedulePosition ${index}, ${assetListIndex} (${scheduledItem ? segmentToString(scheduledItem) : scheduledItem}) pos: ${this.timelinePos}`,
11291137
);
11301138
// Cleanup current item / asset
11311139
const currentItem = this.waitingItem || this.playingItem;
@@ -1395,6 +1403,7 @@ export default class InterstitialsController
13951403
timelinePos >= scheduledItem.end
13961404
) {
13971405
timelinePos = this.getPrimaryResumption(scheduledItem, index);
1406+
this.log(timelineMessage('resumePrimary', timelinePos));
13981407
this.timelinePos = timelinePos;
13991408
}
14001409
this.attachPrimary(timelinePos, scheduledItem);
@@ -1475,6 +1484,7 @@ export default class InterstitialsController
14751484
}
14761485
if (!skipSeekToStartPosition) {
14771486
// Set primary position to resume time
1487+
this.log(timelineMessage('attachPrimary', timelinePos));
14781488
this.timelinePos = timelinePos;
14791489
this.startLoadingPrimaryAt(timelinePos, skipSeekToStartPosition);
14801490
}
@@ -1762,11 +1772,11 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
17621772
if (playingItem) {
17631773
this.trimInPlace(updatedPlayingItem, playingItem);
17641774
}
1765-
if (bufferingItem) {
1775+
if (bufferingItem && updatedBufferingItem !== updatedPlayingItem) {
17661776
this.trimInPlace(updatedBufferingItem, bufferingItem);
17671777
}
17681778

1769-
// Check is buffered to new Interstitial event boundary
1779+
// Check if buffered to new Interstitial event boundary
17701780
// (Live update publishes Interstitial with new segment)
17711781
this.checkBuffer();
17721782
}
@@ -1809,7 +1819,11 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
18091819
bufferInfo.end > flushStart ||
18101820
(bufferInfo.nextStart || 0) > flushStart
18111821
) {
1812-
this.attachPrimary(flushStart, null);
1822+
this.log(
1823+
`trim buffered interstitial ${segmentToString(updatedItem)} (was ${segmentToString(itemBeforeUpdate)})`,
1824+
);
1825+
const skipSeekToStartPosition = true;
1826+
this.attachPrimary(flushStart, null, skipSeekToStartPosition);
18131827
this.flushFrontBuffer(flushStart);
18141828
}
18151829
}
@@ -2486,10 +2500,10 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
24862500
) {
24872501
const playerIndex = this.getAssetPlayerQueueIndex(assetId);
24882502
if (playerIndex !== -1) {
2503+
const player = this.playerQueue[playerIndex];
24892504
this.log(
2490-
`clear asset player "${assetId}" toSegment: ${toSegment ? segmentToString(toSegment) : toSegment}`,
2505+
`clear ${player} toSegment: ${toSegment ? segmentToString(toSegment) : toSegment}`,
24912506
);
2492-
const player = this.playerQueue[playerIndex];
24932507
this.transferMediaFromPlayer(player, toSegment);
24942508
this.playerQueue.splice(playerIndex, 1);
24952509
player.destroy();

0 commit comments

Comments
 (0)