From f5b78dc88ab15fbc23a1133578d6db9597a76c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Fri, 23 Aug 2024 12:34:44 +0200 Subject: [PATCH] feat(Ads): Added advanced type to ad requests (#7196) --- lib/ads/interstitial_ad_manager.js | 20 +++++++++---- lib/ads/media_tailor_ad_manager.js | 48 ++++++++++++++++++++---------- lib/net/networking_engine.js | 6 ++++ 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/lib/ads/interstitial_ad_manager.js b/lib/ads/interstitial_ad_manager.js index 347be51aa2..7da05e4cdf 100644 --- a/lib/ads/interstitial_ad_manager.js +++ b/lib/ads/interstitial_ad_manager.js @@ -275,7 +275,11 @@ shaka.ads.InterstitialAdManager = class { * @return {!Promise} */ async addAdUrlInterstitial(url) { - const responseData = await this.makeAdRequest_(url); + const NetworkingEngine = shaka.net.NetworkingEngine; + const context = { + type: NetworkingEngine.AdvancedRequestType.INTERSTITIAL_AD_URL, + }; + const responseData = await this.makeAdRequest_(url, context); const data = shaka.util.TXml.parseXml(responseData, 'VAST,vmap:VMAP'); if (!data) { throw new shaka.util.Error( @@ -290,7 +294,7 @@ shaka.ads.InterstitialAdManager = class { } else if (data.tagName == 'vmap:VMAP') { for (const ad of shaka.ads.Utils.parseVMAP(data)) { // eslint-disable-next-line no-await-in-loop - const vastResponseData = await this.makeAdRequest_(ad.uri); + const vastResponseData = await this.makeAdRequest_(ad.uri, context); const vast = shaka.util.TXml.parseXml(vastResponseData, 'VAST'); if (!vast) { throw new shaka.util.Error( @@ -762,7 +766,11 @@ shaka.ads.InterstitialAdManager = class { return interstitialsAd; } try { - const responseData = await this.makeAdRequest_(uri); + const NetworkingEngine = shaka.net.NetworkingEngine; + const context = { + type: NetworkingEngine.AdvancedRequestType.INTERSTITIAL_ASSET_LIST, + }; + const responseData = await this.makeAdRequest_(uri, context); const data = shaka.util.StringUtils.fromUTF8(responseData); const dataAsJson = /** @type {!shaka.ads.InterstitialAdManager.AssetsList} */ ( @@ -845,15 +853,17 @@ shaka.ads.InterstitialAdManager = class { /** * @param {string} url + * @param {shaka.extern.RequestContext=} context * @return {!Promise.} * @private */ - async makeAdRequest_(url) { + async makeAdRequest_(url, context) { const type = shaka.net.NetworkingEngine.RequestType.ADS; const request = shaka.net.NetworkingEngine.makeRequest( [url], shaka.net.NetworkingEngine.defaultRetryParameters()); - const op = this.basePlayer_.getNetworkingEngine().request(type, request); + const op = this.basePlayer_.getNetworkingEngine() + .request(type, request, context); const response = await op.promise; return response.data; } diff --git a/lib/ads/media_tailor_ad_manager.js b/lib/ads/media_tailor_ad_manager.js index 4ceb4aed50..527df44d87 100755 --- a/lib/ads/media_tailor_ad_manager.js +++ b/lib/ads/media_tailor_ad_manager.js @@ -202,17 +202,21 @@ shaka.ads.MediaTailorAdManager = class { * @private */ async requestSessionInfo_(url, adsParams) { - const type = shaka.net.NetworkingEngine.RequestType.ADS; - const request = shaka.net.NetworkingEngine.makeRequest( + const NetworkingEngine = shaka.net.NetworkingEngine; + const type = NetworkingEngine.RequestType.ADS; + const context = { + type: NetworkingEngine.AdvancedRequestType.MEDIATAILOR_SESSION_INFO, + }; + const request = NetworkingEngine.makeRequest( [url], - shaka.net.NetworkingEngine.defaultRetryParameters()); + NetworkingEngine.defaultRetryParameters()); request.method = 'POST'; if (adsParams) { const body = JSON.stringify(adsParams); request.body = shaka.util.StringUtils.toUTF8(body); } - const op = this.networkingEngine_.request(type, request); + const op = this.networkingEngine_.request(type, request, context); try { const response = await op.promise; const data = shaka.util.StringUtils.fromUTF8(response.data); @@ -254,12 +258,16 @@ shaka.ads.MediaTailorAdManager = class { * @private */ async requestTrackingInfo_(trackingUrl, firstRequest) { - const type = shaka.net.NetworkingEngine.RequestType.ADS; - const request = shaka.net.NetworkingEngine.makeRequest( + const NetworkingEngine = shaka.net.NetworkingEngine; + const type = NetworkingEngine.RequestType.ADS; + const context = { + type: NetworkingEngine.AdvancedRequestType.MEDIATAILOR_TRACKING_INFO, + }; + const request = NetworkingEngine.makeRequest( [trackingUrl], - shaka.net.NetworkingEngine.defaultRetryParameters()); + NetworkingEngine.defaultRetryParameters()); - const op = this.networkingEngine_.request(type, request); + const op = this.networkingEngine_.request(type, request, context); try { const response = await op.promise; let cuepoints = []; @@ -311,12 +319,16 @@ shaka.ads.MediaTailorAdManager = class { return; } - const type = shaka.net.NetworkingEngine.RequestType.ADS; - const request = shaka.net.NetworkingEngine.makeRequest( + const NetworkingEngine = shaka.net.NetworkingEngine; + const type = NetworkingEngine.RequestType.ADS; + const context = { + type: NetworkingEngine.AdvancedRequestType.MEDIATAILOR_STATIC_RESOURCE, + }; + const request = NetworkingEngine.makeRequest( [nonLinearAd.staticResource], - shaka.net.NetworkingEngine.defaultRetryParameters()); + NetworkingEngine.defaultRetryParameters()); - const op = this.networkingEngine_.request(type, request); + const op = this.networkingEngine_.request(type, request, context); try { this.staticResources_.set(cacheKey, []); const response = await op.promise; @@ -709,16 +721,20 @@ shaka.ads.MediaTailorAdManager = class { (event) => event.eventType == eventType); } if (trackingEvent) { - const type = shaka.net.NetworkingEngine.RequestType.ADS; + const NetworkingEngine = shaka.net.NetworkingEngine; + const type = NetworkingEngine.RequestType.ADS; + const context = { + type: NetworkingEngine.AdvancedRequestType.MEDIATAILOR_TRACKING_EVENT, + }; for (const beaconUrl of trackingEvent.beaconUrls) { if (!beaconUrl || beaconUrl == '') { continue; } - const request = shaka.net.NetworkingEngine.makeRequest( + const request = NetworkingEngine.makeRequest( [beaconUrl], - shaka.net.NetworkingEngine.defaultRetryParameters()); + NetworkingEngine.defaultRetryParameters()); request.method = 'POST'; - this.networkingEngine_.request(type, request); + this.networkingEngine_.request(type, request, context); } } switch (eventType) { diff --git a/lib/net/networking_engine.js b/lib/net/networking_engine.js index cdaf5ee74e..2b399360a0 100644 --- a/lib/net/networking_engine.js +++ b/lib/net/networking_engine.js @@ -886,6 +886,12 @@ shaka.net.NetworkingEngine.AdvancedRequestType = { 'MPD': 4, 'MSS': 5, 'MPD_PATCH': 6, + 'MEDIATAILOR_SESSION_INFO': 7, + 'MEDIATAILOR_TRACKING_INFO': 8, + 'MEDIATAILOR_STATIC_RESOURCE': 9, + 'MEDIATAILOR_TRACKING_EVENT': 10, + 'INTERSTITIAL_ASSET_LIST': 11, + 'INTERSTITIAL_AD_URL': 12, };