Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Ads): Add support for X-TIMELINE-OCCUPIES #6806

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,15 @@ shaka.ads.InterstitialAdManager = class {
const updateBaseVideoTime = () => {
if (!this.usingBaseVideo_) {
if (interstitial.resumeOffset == null) {
const now = Date.now();
this.baseVideo_.currentTime += (now - initialTime) / 1000;
initialTime = now;
if (interstitial.timelineRange && interstitial.endTime) {
if (this.baseVideo_.currentTime != interstitial.endTime) {
this.baseVideo_.currentTime = interstitial.endTime;
}
} else {
const now = Date.now();
this.baseVideo_.currentTime += (now - initialTime) / 1000;
initialTime = now;
}
}
}
};
Expand Down Expand Up @@ -414,7 +420,11 @@ shaka.ads.InterstitialAdManager = class {
if (this.usingBaseVideo_) {
let offset = interstitial.resumeOffset;
if (offset == null) {
offset = (Date.now() - initialTime) / 1000;
if (interstitial.timelineRange && interstitial.endTime) {
offset = interstitial.endTime - (this.lastTime_ || 0);
avelad marked this conversation as resolved.
Show resolved Hide resolved
} else {
offset = (Date.now() - initialTime) / 1000;
}
}
this.onEvent_(new shaka.util.FakeEvent(
shaka.ads.AdManager.AD_CONTENT_RESUME_REQUESTED,
Expand Down Expand Up @@ -560,6 +570,7 @@ shaka.ads.InterstitialAdManager = class {
isSkippable = !data.includes('SKIP');
canJump = !data.includes('JUMP');
}
isSkippable = true;
let resumeOffset = null;
const resume = interstitial.values.find((v) => v.key == 'X-RESUME-OFFSET');
if (resume) {
Expand Down Expand Up @@ -588,6 +599,15 @@ shaka.ads.InterstitialAdManager = class {
pre = data.includes('PRE');
post = data.includes('POST');
}
let timelineRange = true;
const timelineOccupies =
interstitial.values.find((v) => v.key == 'X-TIMELINE-OCCUPIES');
if (timelineOccupies) {
const data = /** @type {string} */(timelineOccupies.data);
timelineRange = data.includes('RANGE');
} else if (!resume && this.basePlayer_.isLive()) {
timelineRange = true;
}
if (assetUri) {
const uri = /** @type {string} */(assetUri.data);
if (!uri) {
Expand All @@ -604,6 +624,7 @@ shaka.ads.InterstitialAdManager = class {
once,
pre,
post,
timelineRange,
});
} else if (assetList) {
const uri = /** @type {string} */(assetList.data);
Expand Down Expand Up @@ -634,6 +655,7 @@ shaka.ads.InterstitialAdManager = class {
once,
pre,
post,
timelineRange,
});
}
}
Expand Down Expand Up @@ -663,6 +685,8 @@ shaka.ads.InterstitialAdManager = class {
} else if (interstitial.post) {
shakaCuePoint.start = -1;
shakaCuePoint.end = null;
} else if (interstitial.timelineRange) {
shakaCuePoint.end = interstitial.endTime;
}
const isValid = !cuePoints.find((c) => {
return shakaCuePoint.start == c.start && shakaCuePoint.end == c.end;
Expand Down Expand Up @@ -725,7 +749,8 @@ shaka.ads.InterstitialAdManager.Asset;
* playoutLimit: ?number,
* once: boolean,
* pre: boolean,
* post: boolean
* post: boolean,
* timelineRange: boolean
* }}
*
* @property {number} startTime
Expand All @@ -738,5 +763,6 @@ shaka.ads.InterstitialAdManager.Asset;
* @property {boolean} once
* @property {boolean} pre
* @property {boolean} post
* @property {boolean} timelineRange
*/
shaka.ads.InterstitialAdManager.Interstitial;
Loading