Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Ads): Add ads config #5085

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions externs/shaka/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ shaka.extern.IAdManager = class extends EventTarget {
*/
setLocale(locale) {}

/**
* Called by the Player to provide an updated configuration any time it
* changes.
* Must be called at least once before init*().
*
* @param {shaka.extern.AdsConfiguration} config
*/
configure(config) {}

release() {}

onAssetUnload() {}
Expand Down
14 changes: 14 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,17 @@ shaka.extern.StreamingConfiguration;
shaka.extern.MediaSourceConfiguration;


/**
* @typedef {Object}
*
* @description
* Ads configuration.
*
* @exportDoc
*/
shaka.extern.AdsConfiguration;


/**
* @typedef {{
* enabled: boolean,
Expand Down Expand Up @@ -1323,6 +1334,7 @@ shaka.extern.OfflineConfiguration;

/**
* @typedef {{
* ads: shaka.extern.AdsConfiguration,
* autoShowText: shaka.config.AutoShowText,
* drm: shaka.extern.DrmConfiguration,
* manifest: shaka.extern.ManifestConfiguration,
Expand All @@ -1349,6 +1361,8 @@ shaka.extern.OfflineConfiguration;
* textDisplayFactory: shaka.extern.TextDisplayer.Factory
* }}
*
* @property {shaka.extern.AdsConfiguration} ads
* Ads configuration and settings.
* @property {shaka.config.AutoShowText} autoShowText
* Controls behavior of auto-showing text tracks on load().
* @property {shaka.extern.DrmConfiguration} drm
Expand Down
24 changes: 24 additions & 0 deletions lib/ads/ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

goog.provide('shaka.ads.AdManager');

goog.require('goog.asserts');
goog.require('shaka.Player');
goog.require('shaka.ads.AdsStats');
goog.require('shaka.ads.ClientSideAdManager');
Expand Down Expand Up @@ -385,6 +386,8 @@ shaka.ads.AdManager = class extends shaka.util.FakeEventTarget {
this.stats_ = new shaka.ads.AdsStats();
/** @private {string} locale */
this.locale_ = navigator.language;
/** @private {?shaka.extern.AdsConfiguration} */
this.config_ = null;
}


Expand All @@ -397,6 +400,21 @@ shaka.ads.AdManager = class extends shaka.util.FakeEventTarget {
}


/**
* @override
* @export
*/
configure(config) {
this.config_ = config;
if (this.csAdManager_) {
this.csAdManager_.configure(this.config_);
}
if (this.ssAdManager_) {
this.csAdManager_.configure(this.config_);
}
}


/**
* @override
* @export
Expand Down Expand Up @@ -443,6 +461,9 @@ shaka.ads.AdManager = class extends shaka.util.FakeEventTarget {
}
this.dispatchEvent(event);
});

goog.asserts.assert(this.config_, 'Config must not be null!');
this.csAdManager_.configure(this.config_);
}


Expand Down Expand Up @@ -544,6 +565,9 @@ shaka.ads.AdManager = class extends shaka.util.FakeEventTarget {
}
this.dispatchEvent(event);
});

goog.asserts.assert(this.config_, 'Config must not be null!');
this.ssAdManager_.configure(this.config_);
}


Expand Down
13 changes: 13 additions & 0 deletions lib/ads/client_side_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ shaka.ads.ClientSideAdManager = class {
/** @private {HTMLMediaElement} */
this.video_ = video;

/** @private {?shaka.extern.AdsConfiguration} */
this.config_ = null;

/** @private {ResizeObserver} */
this.resizeObserver_ = null;

Expand Down Expand Up @@ -84,6 +87,16 @@ shaka.ads.ClientSideAdManager = class {
});
}

/**
* Called by the AdManager to provide an updated configuration any time it
* changes.
*
* @param {shaka.extern.AdsConfiguration} config
*/
configure(config) {
this.config_ = config;
}

/**
* @param {!google.ima.AdsRequest} imaRequest
*/
Expand Down
13 changes: 13 additions & 0 deletions lib/ads/server_side_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ shaka.ads.ServerSideAdManager = class {
/** @private {HTMLMediaElement} */
this.video_ = video;

/** @private {?shaka.extern.AdsConfiguration} */
this.config_ = null;

/** @private
{?shaka.util.PublicPromise.<string>} */
this.streamPromise_ = null;
Expand Down Expand Up @@ -168,6 +171,16 @@ shaka.ads.ServerSideAdManager = class {
});
}

/**
* Called by the AdManager to provide an updated configuration any time it
* changes.
*
* @param {shaka.extern.AdsConfiguration} config
*/
configure(config) {
this.config_ = config;
}

/**
* @param {!google.ima.dai.api.StreamRequest} streamRequest
* @param {string=} backupUrl
Expand Down
3 changes: 3 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3308,6 +3308,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.config_.playRangeStart,
this.config_.playRangeEnd);
}
if (this.adManager_) {
this.adManager_.configure(this.config_.ads);
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ shaka.util.PlayerConfiguration = class {
forceTransmux: false,
};

const ads = {};

const AutoShowText = shaka.config.AutoShowText;

/** @type {shaka.extern.PlayerConfiguration} */
Expand Down Expand Up @@ -333,6 +335,7 @@ shaka.util.PlayerConfiguration = class {
textDisplayFactory: () => null,
cmcd: cmcd,
lcevc: lcevc,
ads: ads,
};

// Add this callback so that we can reference the preferred audio language
Expand Down
3 changes: 3 additions & 0 deletions test/ads/ad_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ describe('Ad manager', () => {
adManager = player.getAdManager();
expect(adManager instanceof shaka.ads.AdManager).toBe(true);

const config = shaka.util.PlayerConfiguration.createDefault().ads;
adManager.configure(config);

adContainer =
/** @type {!HTMLElement} */ (document.createElement('div'));
});
Expand Down
3 changes: 3 additions & 0 deletions test/test/util/fake_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ shaka.test.FakeAdManager = class extends shaka.util.FakeEventTarget {
/** @override */
setLocale(locale) {}

/** @override */
configure(config) {}

/** @override */
initClientSide(adContainer, video) {}

Expand Down