Skip to content

Commit

Permalink
feat(Ads): Support HTMLResource on non-linear VAST ads (#7710)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Dec 4, 2024
1 parent 072acf0 commit 6f4d2d2
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lib/ads/ad_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,29 @@ shaka.ads.Utils = class {
*/
static processNonLinearAd_(interstitials, currentTime, nonLinear) {
const TXml = shaka.util.TXml;
const staticResource = TXml.findChild(nonLinear, 'StaticResource');
if (!staticResource) {
return;
let mimeType = null;
let resource = TXml.findChild(nonLinear, 'StaticResource');
if (resource) {
mimeType = resource.attributes['creativeType'];
} else {
resource = TXml.findChild(nonLinear, 'HTMLResource');
if (!resource) {
return;
}
mimeType = 'text/html';
}
const adUrl = TXml.getContents(staticResource);
let adUrl = TXml.getContents(resource);
if (!adUrl) {
return;
}
const width = TXml.parseAttr(nonLinear, 'width', TXml.parseInt);
const height = TXml.parseAttr(nonLinear, 'height', TXml.parseInt);
if (!width || !height) {
if (mimeType === 'text/html') {
adUrl = 'data:text/html;charset=UTF-8,' + encodeURIComponent(adUrl);
}
const width = TXml.parseAttr(nonLinear, 'width', TXml.parseInt) ||
TXml.parseAttr(nonLinear, 'expandedWidth', TXml.parseInt);
const height = TXml.parseAttr(nonLinear, 'height', TXml.parseInt) ||
TXml.parseAttr(nonLinear, 'expandedHeight', TXml.parseInt);
if (!width && !height) {
return;
}
let playoutLimit = null;
Expand All @@ -158,7 +170,7 @@ shaka.ads.Utils = class {
startTime: startTime,
endTime: null,
uri: adUrl,
mimeType: staticResource.attributes['creativeType'] || null,
mimeType,
isSkippable: false,
skipOffset: null,
skipFor: null,
Expand All @@ -180,8 +192,8 @@ shaka.ads.Utils = class {
y: 0,
},
size: {
x: width,
y: height,
x: width || 0,
y: height || 0,
},
},
});
Expand Down

0 comments on commit 6f4d2d2

Please sign in to comment.