mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-25 17:45:03 +03:00
feat(Ads): Allow multiple calls to requestAds in CS (#5542)
This commit is contained in:
committed by
GitHub
parent
4428adf4c1
commit
837e0fba42
@@ -80,7 +80,7 @@ shaka.ads.ClientSideAdManager = class {
|
||||
this.adsRenderingSettings_ =
|
||||
adsRenderingSettings || new google.ima.AdsRenderingSettings();
|
||||
|
||||
this.eventManager_.listenOnce(this.adsLoader_,
|
||||
this.eventManager_.listen(this.adsLoader_,
|
||||
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, (e) => {
|
||||
this.onAdsManagerLoaded_(
|
||||
/** @type {!google.ima.AdsManagerLoadedEvent} */ (e));
|
||||
@@ -119,6 +119,17 @@ shaka.ads.ClientSideAdManager = class {
|
||||
imaRequest.adTagUrl || imaRequest.adsResponse,
|
||||
'The ad tag needs to be set up before requesting ads, ' +
|
||||
'or adsResponse must be filled.');
|
||||
// Destroy the current AdsManager, in case the tag you requested previously
|
||||
// contains post-rolls (don't play those now).
|
||||
if (this.imaAdsManager_) {
|
||||
this.imaAdsManager_.destroy();
|
||||
}
|
||||
// Your AdsLoader will be set up on page-load. You should re-use the same
|
||||
// AdsLoader for every request.
|
||||
if (this.adsLoader_) {
|
||||
// Reset the IMA SDK.
|
||||
this.adsLoader_.contentComplete();
|
||||
}
|
||||
this.requestAdsStartTime_ = Date.now() / 1000;
|
||||
this.adsLoader_.requestAds(imaRequest);
|
||||
}
|
||||
|
||||
@@ -88,6 +88,10 @@ describe('Ad manager', () => {
|
||||
requestAds(imaRequest) {
|
||||
numAdsRequested += 1;
|
||||
}
|
||||
|
||||
contentComplete() {
|
||||
// Nothing
|
||||
}
|
||||
};
|
||||
window['google'].ima.AdsLoader = mockAdsLoader;
|
||||
|
||||
@@ -102,6 +106,10 @@ describe('Ad manager', () => {
|
||||
/** @type {!google.ima.AdsManager} */ (this);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
getCuePoints() {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user