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

skipoffset added to AttachPodAds #85

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
3 changes: 3 additions & 0 deletions api/ClientRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ClientRequest {
// Private fields
#consent;
#requestedDuration;
#skipoffset;
#userId;
#operatingSystem;
#deviceType;
Expand All @@ -18,6 +19,7 @@ class ClientRequest {
constructor(params) {
this.#consent = params.c || null;
this.#requestedDuration = params.dur || null;
this.#skipoffset = params.skip || null;
this.#userId = params.uid || null;
this.#operatingSystem = params.os || null;
this.#deviceType = params.dt || null;
Expand All @@ -41,6 +43,7 @@ class ClientRequest {
const properties = {
Consent: this.#consent,
RequestedDuration: this.#requestedDuration,
Skipoffset: this.#skipoffset,
UserId: this.#userId,
OperatingSystem: this.#operatingSystem,
DeviceType: this.#deviceType,
Expand Down
1 change: 1 addition & 0 deletions api/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Session {
const vastObj = VastBuilder({
sessionId: this.sessionId,
desiredDuration: params.dur || "0",
skipoffset: params.skip || null,
adserverHostname: this.host,
maxPodDuration: params.max || null,
minPodDuration: params.min || null,
Expand Down
10 changes: 10 additions & 0 deletions api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ const vastSchema = () => ({
Linear: {
type: "object",
properties: {
skipoffset: {
type: "string",
example: "00:00:05",
xml: { attribute: true },
},
Duration: {
type: "string",
example: "00:00:30",
Expand Down Expand Up @@ -575,6 +580,11 @@ const schemas = {
description: "Desired duration in seconds.",
example: "60",
},
skip: {
type: "string",
description: "Skipoffset in seconds or percentage.",
example: "00:00:05 or 25%",
},
uid: {
type: "string",
description: "User ID.",
Expand Down
12 changes: 11 additions & 1 deletion utils/vast-maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ function AttachPodAds(vast, podAds, params) {
}
);
}
console.log("VAST params: ", params);
mediaNode = mediaNode
.attachLinear()
.attachLinear({skipoffset: isValidSkipOffset(params.skipoffset)}) // skipoffset does not seem to exist on VAST 2.0 and lower, you could also have skipoffset in percentage
.attachTrackingEvents()
.addTracking(`http://${params.adserverHostname}/api/v1/sessions/${params.sessionId}/tracking?${adId}=${podAds[i].id}_${i + 1}&progress=0`, { event: "start" })
.addTracking(`http://${params.adserverHostname}/api/v1/sessions/${params.sessionId}/tracking?${adId}=${podAds[i].id}_${i + 1}&progress=25`, { event: "firstQuartile" })
Expand Down Expand Up @@ -351,6 +352,15 @@ function indexOfSmallest(a) {
return lowest;
}

// Validate params.skipoffset is a valid VAST skipoffset value ("x%" or "hh:mm:ss").
function isValidSkipOffset(skipoffset) {
// "hh:mm:ss"
const timeFormatRegex = /^(\d{2}):([0-5][0-9]):([0-5][0-9])$/;
// "x%"
const percentageFormatRegex = /^(100|[1-9]?[0-9])%$/;
return timeFormatRegex.test(skipoffset) || percentageFormatRegex.test(skipoffset) ? skipoffset: null;
}

function PopulatePod(_size, _min, _max, _ads, _chosenAds, _method, _targetDur) {
// Base Case #1: Regardless of current Pod size, return if Pod duration is greater than _max!
if (_chosenAds.length > 0) {
Expand Down
Loading