Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Ads): Support HTMLResource on non-linear VAST ads #7710

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading