-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vast): create PauseAdVastBuilder
- Create new file utils/pause-ad-vast-maker.js - Implement PauseAdVastBuilder function
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |