Skip to content

Commit 6f4d2d2

Browse files
authored
feat(Ads): Support HTMLResource on non-linear VAST ads (#7710)
1 parent 072acf0 commit 6f4d2d2

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

lib/ads/ad_utils.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,29 @@ shaka.ads.Utils = class {
130130
*/
131131
static processNonLinearAd_(interstitials, currentTime, nonLinear) {
132132
const TXml = shaka.util.TXml;
133-
const staticResource = TXml.findChild(nonLinear, 'StaticResource');
134-
if (!staticResource) {
135-
return;
133+
let mimeType = null;
134+
let resource = TXml.findChild(nonLinear, 'StaticResource');
135+
if (resource) {
136+
mimeType = resource.attributes['creativeType'];
137+
} else {
138+
resource = TXml.findChild(nonLinear, 'HTMLResource');
139+
if (!resource) {
140+
return;
141+
}
142+
mimeType = 'text/html';
136143
}
137-
const adUrl = TXml.getContents(staticResource);
144+
let adUrl = TXml.getContents(resource);
138145
if (!adUrl) {
139146
return;
140147
}
141-
const width = TXml.parseAttr(nonLinear, 'width', TXml.parseInt);
142-
const height = TXml.parseAttr(nonLinear, 'height', TXml.parseInt);
143-
if (!width || !height) {
148+
if (mimeType === 'text/html') {
149+
adUrl = 'data:text/html;charset=UTF-8,' + encodeURIComponent(adUrl);
150+
}
151+
const width = TXml.parseAttr(nonLinear, 'width', TXml.parseInt) ||
152+
TXml.parseAttr(nonLinear, 'expandedWidth', TXml.parseInt);
153+
const height = TXml.parseAttr(nonLinear, 'height', TXml.parseInt) ||
154+
TXml.parseAttr(nonLinear, 'expandedHeight', TXml.parseInt);
155+
if (!width && !height) {
144156
return;
145157
}
146158
let playoutLimit = null;
@@ -158,7 +170,7 @@ shaka.ads.Utils = class {
158170
startTime: startTime,
159171
endTime: null,
160172
uri: adUrl,
161-
mimeType: staticResource.attributes['creativeType'] || null,
173+
mimeType,
162174
isSkippable: false,
163175
skipOffset: null,
164176
skipFor: null,
@@ -180,8 +192,8 @@ shaka.ads.Utils = class {
180192
y: 0,
181193
},
182194
size: {
183-
x: width,
184-
y: height,
195+
x: width || 0,
196+
y: height || 0,
185197
},
186198
},
187199
});

0 commit comments

Comments
 (0)