Skip to content

Commit

Permalink
feat(vast): create PauseAdVastBuilder
Browse files Browse the repository at this point in the history
- Create new file utils/pause-ad-vast-maker.js
- Implement PauseAdVastBuilder function
  • Loading branch information
AxelHolst committed Jul 1, 2024
1 parent a89c025 commit 6eb8cde
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions utils/pause-ad-vast-maker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const createVast = require('vast-builder');

function PauseAdVastBuilder(params) {
let vast = null;

switch (params.version) {
case "2":
vast = createVast.v2();
break;
case "3":
vast = createVast.v3();
break;
default:
vast = createVast.v4();
break;
}

const adId = vast.attrs.version === "4.0" ? "adId" : "adID";

// Use provided width and height, or default to 300x167
const width = params.width || 300;
const height = params.height || 167;

vast
.attachAd({ id: "pause-ad-1" })
.attachInLine()
.addAdSystem("Test Adserver")
.addAdTitle("Pause Ad")
.addImpression(`http://${params.adserverHostname}/api/v1/sessions/${params.sessionId}/tracking?${adId}=pause-ad&progress=vast`, { id: "pause-ad-impression-1" })
.attachCreatives()
.attachCreative({ id: "pause-ad-creative-1", [adId]: "pause-ad" })
.attachNonLinearAds()
.attachTrackingEvents()
.addTracking(`http://${params.adserverHostname}/api/v1/sessions/${params.sessionId}/tracking?${adId}=pause-ad&progress=0`, { event: "start" })
.addTracking(`http://${params.adserverHostname}/api/v1/sessions/${params.sessionId}/tracking?${adId}=pause-ad&progress=100`, { event: "complete" })
.addTracking(`http://${params.adserverHostname}/api/v1/sessions/${params.sessionId}/tracking?${adId}=pause-ad&event=pause`, { event: "pause" })
.and()
.attachNonLinear({
id: "pause-ad-1",
width: width,
height: height,
scalable: true,
maintainAspectRatio: true,
minSuggestedDuration: "00:00:05",
apiFramework: "static",
})
.addStaticResource("https://testcontent.eyevinn.technology/ads/STSWE_AD_001.jpg", "image/jpeg")
.addNonLinearClickThrough("https://github.com/Eyevinn/test-adserver");

const vastXml = vast.toXml();
console.log('Generated VAST XML:', vastXml);
return { xml: vastXml };
}

module.exports = { PauseAdVastBuilder };

0 comments on commit 6eb8cde

Please sign in to comment.