Skip to content

Commit f5b78dc

Browse files
authored
feat(Ads): Added advanced type to ad requests (#7196)
1 parent 230bd90 commit f5b78dc

File tree

3 files changed

+53
-21
lines changed

3 files changed

+53
-21
lines changed

lib/ads/interstitial_ad_manager.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,11 @@ shaka.ads.InterstitialAdManager = class {
275275
* @return {!Promise}
276276
*/
277277
async addAdUrlInterstitial(url) {
278-
const responseData = await this.makeAdRequest_(url);
278+
const NetworkingEngine = shaka.net.NetworkingEngine;
279+
const context = {
280+
type: NetworkingEngine.AdvancedRequestType.INTERSTITIAL_AD_URL,
281+
};
282+
const responseData = await this.makeAdRequest_(url, context);
279283
const data = shaka.util.TXml.parseXml(responseData, 'VAST,vmap:VMAP');
280284
if (!data) {
281285
throw new shaka.util.Error(
@@ -290,7 +294,7 @@ shaka.ads.InterstitialAdManager = class {
290294
} else if (data.tagName == 'vmap:VMAP') {
291295
for (const ad of shaka.ads.Utils.parseVMAP(data)) {
292296
// eslint-disable-next-line no-await-in-loop
293-
const vastResponseData = await this.makeAdRequest_(ad.uri);
297+
const vastResponseData = await this.makeAdRequest_(ad.uri, context);
294298
const vast = shaka.util.TXml.parseXml(vastResponseData, 'VAST');
295299
if (!vast) {
296300
throw new shaka.util.Error(
@@ -762,7 +766,11 @@ shaka.ads.InterstitialAdManager = class {
762766
return interstitialsAd;
763767
}
764768
try {
765-
const responseData = await this.makeAdRequest_(uri);
769+
const NetworkingEngine = shaka.net.NetworkingEngine;
770+
const context = {
771+
type: NetworkingEngine.AdvancedRequestType.INTERSTITIAL_ASSET_LIST,
772+
};
773+
const responseData = await this.makeAdRequest_(uri, context);
766774
const data = shaka.util.StringUtils.fromUTF8(responseData);
767775
const dataAsJson =
768776
/** @type {!shaka.ads.InterstitialAdManager.AssetsList} */ (
@@ -845,15 +853,17 @@ shaka.ads.InterstitialAdManager = class {
845853

846854
/**
847855
* @param {string} url
856+
* @param {shaka.extern.RequestContext=} context
848857
* @return {!Promise.<BufferSource>}
849858
* @private
850859
*/
851-
async makeAdRequest_(url) {
860+
async makeAdRequest_(url, context) {
852861
const type = shaka.net.NetworkingEngine.RequestType.ADS;
853862
const request = shaka.net.NetworkingEngine.makeRequest(
854863
[url],
855864
shaka.net.NetworkingEngine.defaultRetryParameters());
856-
const op = this.basePlayer_.getNetworkingEngine().request(type, request);
865+
const op = this.basePlayer_.getNetworkingEngine()
866+
.request(type, request, context);
857867
const response = await op.promise;
858868
return response.data;
859869
}

lib/ads/media_tailor_ad_manager.js

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,21 @@ shaka.ads.MediaTailorAdManager = class {
202202
* @private
203203
*/
204204
async requestSessionInfo_(url, adsParams) {
205-
const type = shaka.net.NetworkingEngine.RequestType.ADS;
206-
const request = shaka.net.NetworkingEngine.makeRequest(
205+
const NetworkingEngine = shaka.net.NetworkingEngine;
206+
const type = NetworkingEngine.RequestType.ADS;
207+
const context = {
208+
type: NetworkingEngine.AdvancedRequestType.MEDIATAILOR_SESSION_INFO,
209+
};
210+
const request = NetworkingEngine.makeRequest(
207211
[url],
208-
shaka.net.NetworkingEngine.defaultRetryParameters());
212+
NetworkingEngine.defaultRetryParameters());
209213
request.method = 'POST';
210214
if (adsParams) {
211215
const body = JSON.stringify(adsParams);
212216
request.body = shaka.util.StringUtils.toUTF8(body);
213217
}
214218

215-
const op = this.networkingEngine_.request(type, request);
219+
const op = this.networkingEngine_.request(type, request, context);
216220
try {
217221
const response = await op.promise;
218222
const data = shaka.util.StringUtils.fromUTF8(response.data);
@@ -254,12 +258,16 @@ shaka.ads.MediaTailorAdManager = class {
254258
* @private
255259
*/
256260
async requestTrackingInfo_(trackingUrl, firstRequest) {
257-
const type = shaka.net.NetworkingEngine.RequestType.ADS;
258-
const request = shaka.net.NetworkingEngine.makeRequest(
261+
const NetworkingEngine = shaka.net.NetworkingEngine;
262+
const type = NetworkingEngine.RequestType.ADS;
263+
const context = {
264+
type: NetworkingEngine.AdvancedRequestType.MEDIATAILOR_TRACKING_INFO,
265+
};
266+
const request = NetworkingEngine.makeRequest(
259267
[trackingUrl],
260-
shaka.net.NetworkingEngine.defaultRetryParameters());
268+
NetworkingEngine.defaultRetryParameters());
261269

262-
const op = this.networkingEngine_.request(type, request);
270+
const op = this.networkingEngine_.request(type, request, context);
263271
try {
264272
const response = await op.promise;
265273
let cuepoints = [];
@@ -311,12 +319,16 @@ shaka.ads.MediaTailorAdManager = class {
311319
return;
312320
}
313321

314-
const type = shaka.net.NetworkingEngine.RequestType.ADS;
315-
const request = shaka.net.NetworkingEngine.makeRequest(
322+
const NetworkingEngine = shaka.net.NetworkingEngine;
323+
const type = NetworkingEngine.RequestType.ADS;
324+
const context = {
325+
type: NetworkingEngine.AdvancedRequestType.MEDIATAILOR_STATIC_RESOURCE,
326+
};
327+
const request = NetworkingEngine.makeRequest(
316328
[nonLinearAd.staticResource],
317-
shaka.net.NetworkingEngine.defaultRetryParameters());
329+
NetworkingEngine.defaultRetryParameters());
318330

319-
const op = this.networkingEngine_.request(type, request);
331+
const op = this.networkingEngine_.request(type, request, context);
320332
try {
321333
this.staticResources_.set(cacheKey, []);
322334
const response = await op.promise;
@@ -709,16 +721,20 @@ shaka.ads.MediaTailorAdManager = class {
709721
(event) => event.eventType == eventType);
710722
}
711723
if (trackingEvent) {
712-
const type = shaka.net.NetworkingEngine.RequestType.ADS;
724+
const NetworkingEngine = shaka.net.NetworkingEngine;
725+
const type = NetworkingEngine.RequestType.ADS;
726+
const context = {
727+
type: NetworkingEngine.AdvancedRequestType.MEDIATAILOR_TRACKING_EVENT,
728+
};
713729
for (const beaconUrl of trackingEvent.beaconUrls) {
714730
if (!beaconUrl || beaconUrl == '') {
715731
continue;
716732
}
717-
const request = shaka.net.NetworkingEngine.makeRequest(
733+
const request = NetworkingEngine.makeRequest(
718734
[beaconUrl],
719-
shaka.net.NetworkingEngine.defaultRetryParameters());
735+
NetworkingEngine.defaultRetryParameters());
720736
request.method = 'POST';
721-
this.networkingEngine_.request(type, request);
737+
this.networkingEngine_.request(type, request, context);
722738
}
723739
}
724740
switch (eventType) {

lib/net/networking_engine.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,12 @@ shaka.net.NetworkingEngine.AdvancedRequestType = {
886886
'MPD': 4,
887887
'MSS': 5,
888888
'MPD_PATCH': 6,
889+
'MEDIATAILOR_SESSION_INFO': 7,
890+
'MEDIATAILOR_TRACKING_INFO': 8,
891+
'MEDIATAILOR_STATIC_RESOURCE': 9,
892+
'MEDIATAILOR_TRACKING_EVENT': 10,
893+
'INTERSTITIAL_ASSET_LIST': 11,
894+
'INTERSTITIAL_AD_URL': 12,
889895
};
890896

891897

0 commit comments

Comments
 (0)