From 6f4d2d249a4f829db0a627fc06746874d5c7bef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Wed, 4 Dec 2024 08:20:50 +0100 Subject: [PATCH] feat(Ads): Support HTMLResource on non-linear VAST ads (#7710) --- lib/ads/ad_utils.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/ads/ad_utils.js b/lib/ads/ad_utils.js index aec244e8f3..aecd6e8cd9 100644 --- a/lib/ads/ad_utils.js +++ b/lib/ads/ad_utils.js @@ -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; @@ -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, @@ -180,8 +192,8 @@ shaka.ads.Utils = class { y: 0, }, size: { - x: width, - y: height, + x: width || 0, + y: height || 0, }, }, });