From 4fa832724c1b7818a1bbdc42212d9a854d2d4256 Mon Sep 17 00:00:00 2001 From: fhedma Date: Fri, 7 Jun 2024 15:24:18 +0200 Subject: [PATCH 1/4] skipoffset in AttachPodAds Added a attribute to the attachLinear method in AttachPodAds. Right now we set it as 5 seconds but it could be changed to another value or a percentage. We could also make it so that we look for a sent in skipoffset value from the sent in params. --- utils/vast-maker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/vast-maker.js b/utils/vast-maker.js index 4c7d330..224af6d 100644 --- a/utils/vast-maker.js +++ b/utils/vast-maker.js @@ -209,7 +209,7 @@ function AttachPodAds(vast, podAds, params) { ); } mediaNode = mediaNode - .attachLinear() + .attachLinear({ skipoffset: "00:00:05" }) // 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" }) From 3e3d1e32e15a8e5ef740d7e9d728ebc9e311c837 Mon Sep 17 00:00:00 2001 From: fhedma Date: Thu, 13 Jun 2024 14:07:45 +0200 Subject: [PATCH 2/4] Input Parameters for skipoffset I added so you can send in a value for the parameter skipoffset plus a format checker for the parameter. Also added a skipoffset value in the example response in Swagger. --- api/ClientRequest.js | 3 +++ api/Session.js | 1 + api/routes.js | 10 ++++++++++ utils/vast-maker.js | 12 +++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/api/ClientRequest.js b/api/ClientRequest.js index d5e8c38..1de4d56 100644 --- a/api/ClientRequest.js +++ b/api/ClientRequest.js @@ -2,6 +2,7 @@ class ClientRequest { // Private fields #consent; #requestedDuration; + #skipoffset; #userId; #operatingSystem; #deviceType; @@ -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; @@ -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, diff --git a/api/Session.js b/api/Session.js index c70ec26..ce36ae5 100644 --- a/api/Session.js +++ b/api/Session.js @@ -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, diff --git a/api/routes.js b/api/routes.js index afcb6a2..42b9c1f 100644 --- a/api/routes.js +++ b/api/routes.js @@ -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", @@ -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.", diff --git a/utils/vast-maker.js b/utils/vast-maker.js index 224af6d..fb749fe 100644 --- a/utils/vast-maker.js +++ b/utils/vast-maker.js @@ -208,8 +208,9 @@ function AttachPodAds(vast, podAds, params) { } ); } + console.log("VAST params: ", params); mediaNode = mediaNode - .attachLinear({ skipoffset: "00:00:05" }) // skipoffset does not seem to exist on VAST 2.0 and lower, you could also have skipoffset in percentage + .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" }) @@ -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) { From b5ee9c7eb7d1b0fc9bf486a4ad45c4fd5f59e7c2 Mon Sep 17 00:00:00 2001 From: Filip Hedman Date: Sun, 16 Jun 2024 00:40:46 +0200 Subject: [PATCH 3/4] Skipoffset added to VMAP Added so that vmap-maker sends in skipoffset as a param into the VastBuilder. I also added a skipoffset variable into the defaultConfigs in vmap-maker.js. --- api/Session.js | 1 + api/routes.js | 7 ++++++- utils/vast-maker.js | 25 ++++++++++++++++++++----- utils/vmap-maker.js | 2 ++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/api/Session.js b/api/Session.js index ce36ae5..fd9a09b 100644 --- a/api/Session.js +++ b/api/Session.js @@ -43,6 +43,7 @@ class Session { generalVastConfigs: { sessionId: this.sessionId, desiredDuration: params.dur || "0", + skipoffset: params.skip || null, adserverHostname: this.host, maxPodDuration: params.max || null, minPodDuration: params.min || null, diff --git a/api/routes.js b/api/routes.js index 42b9c1f..616c833 100644 --- a/api/routes.js +++ b/api/routes.js @@ -583,7 +583,7 @@ const schemas = { skip: { type: "string", description: "Skipoffset in seconds or percentage.", - example: "00:00:05 or 25%", + example: "5 or 25%", }, uid: { type: "string", @@ -683,6 +683,11 @@ const schemas = { description: "Desired duration for midroll ad break, in seconds.", example: "60", }, + skip: { + type: "string", + description: "Skipoffset in seconds or percentage.", + example: "5 or 25%", + }, uid: { type: "string", description: "User ID.", diff --git a/utils/vast-maker.js b/utils/vast-maker.js index fb749fe..1fd2989 100644 --- a/utils/vast-maker.js +++ b/utils/vast-maker.js @@ -86,6 +86,7 @@ const DEFAULT_AD_LIST = [ * */ function VastBuilder(params) { + console.log("VastBuilder params: ", params); let vastObject = {}; let adList = []; let vast = null; @@ -208,9 +209,8 @@ function AttachPodAds(vast, podAds, params) { } ); } - console.log("VAST params: ", params); mediaNode = mediaNode - .attachLinear({skipoffset: isValidSkipOffset(params.skipoffset)}) // skipoffset does not seem to exist on VAST 2.0 and lower, you could also have skipoffset in percentage + .attachLinear({skipoffset: getSkipOffsetValue(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" }) @@ -352,13 +352,28 @@ function indexOfSmallest(a) { return lowest; } -// Validate params.skipoffset is a valid VAST skipoffset value ("x%" or "hh:mm:ss"). -function isValidSkipOffset(skipoffset) { +// Validate that params.skipoffset is a valid VAST skipoffset value ("x%" or "hh:mm:ss"). +function getSkipOffsetValue(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; + // "seconds" + const integerSecondsRegex = /^\d+$/; + + if (timeFormatRegex.test(skipoffset) || percentageFormatRegex.test(skipoffset)){ + return skipoffset; + } + // convert seconds to "hh:mm:ss" format + if (integerSecondsRegex.test(skipoffset)) { + const totalSeconds = parseInt(skipoffset, 10); + const hours = String(Math.floor(totalSeconds / 3600)).padStart(2, '0'); + const minutes = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0'); + const seconds = String(totalSeconds % 60).padStart(2, '0'); + + return `${hours}:${minutes}:${seconds}`; + } + return null; } function PopulatePod(_size, _min, _max, _ads, _chosenAds, _method, _targetDur) { diff --git a/utils/vmap-maker.js b/utils/vmap-maker.js index a183433..6444f30 100644 --- a/utils/vmap-maker.js +++ b/utils/vmap-maker.js @@ -80,6 +80,7 @@ function VmapBuilder(params) { const defaultConfigs = { sessionId: GVC.sessionId, desiredDuration: "15", + skipoffset: GVC.skipoffset, adserverHostname: GVC.adserverHostname, maxPodDuration: null, minPodDuration: null, @@ -90,6 +91,7 @@ function VmapBuilder(params) { const breakpoints = params.breakpoints ? params.breakpoints.split(",").filter((item) => !isNaN(Number(item))) : []; if (params.preroll) { + //console.log("PARAMS: ",params.generalVastConfigs); const preVast = VastBuilder(defaultConfigs); vmap.attachAdBreak("preroll.ad", "linear", "start", preVast.xml, { sessionId: GVC.sessionId, From fc7cb8589dde00d958fded7249052558e1d730dd Mon Sep 17 00:00:00 2001 From: Filip Hedman Date: Wed, 19 Jun 2024 14:33:32 +0200 Subject: [PATCH 4/4] Clean up Cleaned the code a bit, removed console logs and comments. Also removed the "hh:mm:ss" format check in getSkipOffsetValue function in vast-maker.js. --- utils/vast-maker.js | 6 +----- utils/vmap-maker.js | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/utils/vast-maker.js b/utils/vast-maker.js index 1fd2989..4c5b9f2 100644 --- a/utils/vast-maker.js +++ b/utils/vast-maker.js @@ -86,7 +86,6 @@ const DEFAULT_AD_LIST = [ * */ function VastBuilder(params) { - console.log("VastBuilder params: ", params); let vastObject = {}; let adList = []; let vast = null; @@ -352,16 +351,13 @@ function indexOfSmallest(a) { return lowest; } -// Validate that params.skipoffset is a valid VAST skipoffset value ("x%" or "hh:mm:ss"). function getSkipOffsetValue(skipoffset) { - // "hh:mm:ss" - const timeFormatRegex = /^(\d{2}):([0-5][0-9]):([0-5][0-9])$/; // "x%" const percentageFormatRegex = /^(100|[1-9]?[0-9])%$/; // "seconds" const integerSecondsRegex = /^\d+$/; - if (timeFormatRegex.test(skipoffset) || percentageFormatRegex.test(skipoffset)){ + if (percentageFormatRegex.test(skipoffset)){ return skipoffset; } // convert seconds to "hh:mm:ss" format diff --git a/utils/vmap-maker.js b/utils/vmap-maker.js index 6444f30..85aaa27 100644 --- a/utils/vmap-maker.js +++ b/utils/vmap-maker.js @@ -91,7 +91,6 @@ function VmapBuilder(params) { const breakpoints = params.breakpoints ? params.breakpoints.split(",").filter((item) => !isNaN(Number(item))) : []; if (params.preroll) { - //console.log("PARAMS: ",params.generalVastConfigs); const preVast = VastBuilder(defaultConfigs); vmap.attachAdBreak("preroll.ad", "linear", "start", preVast.xml, { sessionId: GVC.sessionId,