From b5ee9c7eb7d1b0fc9bf486a4ad45c4fd5f59e7c2 Mon Sep 17 00:00:00 2001 From: Filip Hedman Date: Sun, 16 Jun 2024 00:40:46 +0200 Subject: [PATCH] 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,