Skip to content

Commit

Permalink
feat(Ads): Added advanced type to ad requests (#7196)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Aug 23, 2024
1 parent 230bd90 commit f5b78dc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
20 changes: 15 additions & 5 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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} */ (
Expand Down Expand Up @@ -845,15 +853,17 @@ shaka.ads.InterstitialAdManager = class {

/**
* @param {string} url
* @param {shaka.extern.RequestContext=} context
* @return {!Promise.<BufferSource>}
* @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;
}
Expand Down
48 changes: 32 additions & 16 deletions lib/ads/media_tailor_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions lib/net/networking_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};


Expand Down

0 comments on commit f5b78dc

Please sign in to comment.