diff --git a/build/types/ads b/build/types/ads index ceea3a0eec..1a526c8843 100644 --- a/build/types/ads +++ b/build/types/ads @@ -1,6 +1,7 @@ # Ad Insertion Functionality +../../lib/ads/ad_manager.js ++../../lib/ads/ad_utils.js +../../lib/ads/ads_stats.js +../../lib/ads/client_side_ad.js +../../lib/ads/client_side_ad_manager.js diff --git a/docs/tutorials/ad_monetization.md b/docs/tutorials/ad_monetization.md index f89301d4e3..ca7f3333bc 100644 --- a/docs/tutorials/ad_monetization.md +++ b/docs/tutorials/ad_monetization.md @@ -222,7 +222,7 @@ Let's register a simple listener to Shaka's AD_STARTED event. It will log the start of the ad in the console. ```js -adManager.addEventListener(shaka.ads.AdManager.AD_STARTED, () => { +adManager.addEventListener(shaka.ads.Utils.AD_STARTED, () => { console.log('An ad has started'); }); ``` @@ -235,7 +235,7 @@ that requires access to those, here is how to get them: // Note that unlike in the previous example, we are capturing the AD_STARTED // event object here (the "e" parameter of the lambda function) so we can access // its properties. -adManager.addEventListener(shaka.ads.AdManager.AD_STARTED, (e) => { +adManager.addEventListener(shaka.ads.Utils.AD_STARTED, (e) => { const sdkAdObject = e['sdkAdObject']; const originalEvent = e['originalEvent']; }); @@ -250,11 +250,11 @@ Client Side or the {@link shaka.ads.AdManager#event:ImaStreamManagerLoadedEvent} for Server Side to get the IMA [AdManager][] or [StreamManager][] objects. ```js -adManager.addEventListener(shaka.ads.AdManager.IMA_AD_MANAGER_LOADED, (e) => { +adManager.addEventListener(shaka.ads.Utils.IMA_AD_MANAGER_LOADED, (e) => { const imaAdManager = e['imaAdManager']; }); -adManager.addEventListener(shaka.ads.AdManager.IMA_STREAM_MANAGER_LOADED, (e) => { +adManager.addEventListener(shaka.ads.Utils.IMA_STREAM_MANAGER_LOADED, (e) => { const imaStreamManager = e['imaStreamManager']; }); ``` diff --git a/lib/ads/ad_manager.js b/lib/ads/ad_manager.js index d0c007aec2..085a9f402b 100644 --- a/lib/ads/ad_manager.js +++ b/lib/ads/ad_manager.js @@ -14,6 +14,7 @@ goog.require('shaka.ads.AdsStats'); goog.require('shaka.ads.ClientSideAdManager'); goog.require('shaka.ads.InterstitialAdManager'); goog.require('shaka.ads.MediaTailorAdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ads.ServerSideAdManager'); goog.require('shaka.log'); goog.require('shaka.util.Error'); @@ -319,7 +320,7 @@ goog.require('shaka.util.IReleasable'); /** - * @event shaka.ads.AdManager.AD_ERROR + * @event shaka.ads.Utils.AD_ERROR * @description Fired when a fatal error is encountered. * @property {string} type * 'ad-error' @@ -554,9 +555,9 @@ shaka.ads.AdManager = class extends shaka.util.FakeEventTarget { } this.dispatchEvent( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STOPPED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_STOPPED)); this.dispatchEvent(new shaka.util.FakeEvent( - shaka.ads.AdManager.AD_CONTENT_ATTACH_REQUESTED)); + shaka.ads.Utils.AD_CONTENT_ATTACH_REQUESTED)); this.stats_ = new shaka.ads.AdsStats(); } @@ -838,21 +839,21 @@ shaka.ads.AdManager = class extends shaka.util.FakeEventTarget { processAndDispatchEvent_(event) { if (event && event.type) { switch (event.type) { - case shaka.ads.AdManager.ADS_LOADED: { + case shaka.ads.Utils.ADS_LOADED: { const loadTime = (/** @type {!Object} */ (event))['loadTime']; this.stats_.addLoadTime(loadTime); break; } - case shaka.ads.AdManager.AD_STARTED: + case shaka.ads.Utils.AD_STARTED: this.stats_.incrementStarted(); break; - case shaka.ads.AdManager.AD_COMPLETE: + case shaka.ads.Utils.AD_COMPLETE: this.stats_.incrementPlayedCompletely(); break; - case shaka.ads.AdManager.AD_SKIPPED: + case shaka.ads.Utils.AD_SKIPPED: this.stats_.incrementSkipped(); break; - case shaka.ads.AdManager.AD_ERROR: + case shaka.ads.Utils.AD_ERROR: this.stats_.incrementErrors(); break; } @@ -864,16 +865,22 @@ shaka.ads.AdManager = class extends shaka.util.FakeEventTarget { /** * The event name for when a sequence of ads has been loaded. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.ADS_LOADED = 'ads-loaded'; /** * The event name for when an ad has started playing. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_STARTED = 'ad-started'; @@ -881,8 +888,11 @@ shaka.ads.AdManager.AD_STARTED = 'ad-started'; /** * The event name for when an ad playhead crosses first quartile. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_FIRST_QUARTILE = 'ad-first-quartile'; @@ -890,8 +900,11 @@ shaka.ads.AdManager.AD_FIRST_QUARTILE = 'ad-first-quartile'; /** * The event name for when an ad playhead crosses midpoint. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_MIDPOINT = 'ad-midpoint'; @@ -899,8 +912,11 @@ shaka.ads.AdManager.AD_MIDPOINT = 'ad-midpoint'; /** * The event name for when an ad playhead crosses third quartile. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_THIRD_QUARTILE = 'ad-third-quartile'; @@ -908,8 +924,11 @@ shaka.ads.AdManager.AD_THIRD_QUARTILE = 'ad-third-quartile'; /** * The event name for when an ad has completed playing. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_COMPLETE = 'ad-complete'; @@ -919,17 +938,23 @@ shaka.ads.AdManager.AD_COMPLETE = 'ad-complete'; * (played all the way through, was skipped, or was unable to proceed * due to an error). * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_STOPPED = 'ad-stopped'; /** - * The event name for when an ad is skipped by the user.. + * The event name for when an ad is skipped by the user. + * + * Deprecated, please use {@link shaka.ads.Utils} * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_SKIPPED = 'ad-skipped'; @@ -937,8 +962,11 @@ shaka.ads.AdManager.AD_SKIPPED = 'ad-skipped'; /** * The event name for when the ad volume has changed. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_VOLUME_CHANGED = 'ad-volume-changed'; @@ -946,8 +974,11 @@ shaka.ads.AdManager.AD_VOLUME_CHANGED = 'ad-volume-changed'; /** * The event name for when the ad was muted. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_MUTED = 'ad-muted'; @@ -955,8 +986,11 @@ shaka.ads.AdManager.AD_MUTED = 'ad-muted'; /** * The event name for when the ad was paused. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_PAUSED = 'ad-paused'; @@ -964,8 +998,11 @@ shaka.ads.AdManager.AD_PAUSED = 'ad-paused'; /** * The event name for when the ad was resumed after a pause. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_RESUMED = 'ad-resumed'; @@ -974,8 +1011,11 @@ shaka.ads.AdManager.AD_RESUMED = 'ad-resumed'; * The event name for when the ad's skip status changes * (usually it becomes skippable when it wasn't before). * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_SKIP_STATE_CHANGED = 'ad-skip-state-changed'; @@ -984,8 +1024,11 @@ shaka.ads.AdManager.AD_SKIP_STATE_CHANGED = 'ad-skip-state-changed'; * The event name for when the ad's cue points (start/end markers) * have changed. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.CUEPOINTS_CHANGED = 'ad-cue-points-changed'; @@ -994,8 +1037,11 @@ shaka.ads.AdManager.CUEPOINTS_CHANGED = 'ad-cue-points-changed'; * The event name for when the native IMA ad manager object has * loaded and become available. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.IMA_AD_MANAGER_LOADED = 'ima-ad-manager-loaded'; @@ -1004,8 +1050,11 @@ shaka.ads.AdManager.IMA_AD_MANAGER_LOADED = 'ima-ad-manager-loaded'; * The event name for when the native IMA stream manager object has * loaded and become available. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.IMA_STREAM_MANAGER_LOADED = 'ima-stream-manager-loaded'; @@ -1013,8 +1062,11 @@ shaka.ads.AdManager.IMA_STREAM_MANAGER_LOADED = 'ima-stream-manager-loaded'; /** * The event name for when the ad was clicked. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_CLICKED = 'ad-clicked'; @@ -1022,8 +1074,11 @@ shaka.ads.AdManager.AD_CLICKED = 'ad-clicked'; /** * The event name for when there is an update to the current ad's progress. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_PROGRESS = 'ad-progress'; @@ -1031,8 +1086,11 @@ shaka.ads.AdManager.AD_PROGRESS = 'ad-progress'; /** * The event name for when the ad is buffering. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_BUFFERING = 'ad-buffering'; @@ -1040,8 +1098,11 @@ shaka.ads.AdManager.AD_BUFFERING = 'ad-buffering'; /** * The event name for when the ad's URL was hit. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_IMPRESSION = 'ad-impression'; @@ -1049,8 +1110,11 @@ shaka.ads.AdManager.AD_IMPRESSION = 'ad-impression'; /** * The event name for when the ad's duration changed. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_DURATION_CHANGED = 'ad-duration-changed'; @@ -1058,8 +1122,11 @@ shaka.ads.AdManager.AD_DURATION_CHANGED = 'ad-duration-changed'; /** * The event name for when the ad was closed by the user. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_CLOSED = 'ad-closed'; @@ -1067,8 +1134,11 @@ shaka.ads.AdManager.AD_CLOSED = 'ad-closed'; /** * The event name for when the ad data becomes available. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_LOADED = 'ad-loaded'; @@ -1076,8 +1146,11 @@ shaka.ads.AdManager.AD_LOADED = 'ad-loaded'; /** * The event name for when all the ads were completed. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.ALL_ADS_COMPLETED = 'all-ads-completed'; @@ -1085,8 +1158,11 @@ shaka.ads.AdManager.ALL_ADS_COMPLETED = 'all-ads-completed'; /** * The event name for when the ad changes from or to linear. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_LINEAR_CHANGED = 'ad-linear-changed'; @@ -1094,8 +1170,11 @@ shaka.ads.AdManager.AD_LINEAR_CHANGED = 'ad-linear-changed'; /** * The event name for when the ad's metadata becomes available. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_METADATA = 'ad-metadata'; @@ -1104,16 +1183,22 @@ shaka.ads.AdManager.AD_METADATA = 'ad-metadata'; * The event name for when the ad display encountered a recoverable * error. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_RECOVERABLE_ERROR = 'ad-recoverable-error'; /** * The event name for when the ad manager dispatch errors. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_ERROR = 'ad-error'; @@ -1121,8 +1206,11 @@ shaka.ads.AdManager.AD_ERROR = 'ad-error'; * The event name for when the client side SDK signalled its readiness * to play a VPAID ad or an ad rule. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_BREAK_READY = 'ad-break-ready'; @@ -1131,8 +1219,11 @@ shaka.ads.AdManager.AD_BREAK_READY = 'ad-break-ready'; * The event name for when the interaction callback for the ad was * triggered. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_INTERACTION = 'ad-interaction'; @@ -1141,8 +1232,11 @@ shaka.ads.AdManager.AD_INTERACTION = 'ad-interaction'; * The name of the event for when an ad requires the main content to be paused. * Fired when the platform does not support multiple media elements. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_CONTENT_PAUSE_REQUESTED = 'ad-content-pause-requested'; @@ -1151,8 +1245,11 @@ shaka.ads.AdManager.AD_CONTENT_PAUSE_REQUESTED = 'ad-content-pause-requested'; * The name of the event for when an ad requires the main content to be resumed. * Fired when the platform does not support multiple media elements. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_CONTENT_RESUME_REQUESTED = 'ad-content-resume-requested'; @@ -1161,8 +1258,11 @@ shaka.ads.AdManager.AD_CONTENT_RESUME_REQUESTED = 'ad-content-resume-requested'; * The name of the event for when an ad requires the video of the main content * to be attached. * + * Deprecated, please use {@link shaka.ads.Utils} + * * @const {string} * @export + * @deprecated */ shaka.ads.AdManager.AD_CONTENT_ATTACH_REQUESTED = 'ad-content-attach-requested'; diff --git a/lib/ads/ad_utils.js b/lib/ads/ad_utils.js new file mode 100644 index 0000000000..391fbb3a6f --- /dev/null +++ b/lib/ads/ad_utils.js @@ -0,0 +1,323 @@ +/*! @license + * Shaka Player + * Copyright 2016 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + + +goog.provide('shaka.ads.Utils'); + + +/** + * A class responsible for ad utils. + * @export + */ +shaka.ads.Utils = class { + +}; + +/** + * The event name for when a sequence of ads has been loaded. + * + * @const {string} + * @export + */ +shaka.ads.Utils.ADS_LOADED = 'ads-loaded'; + +/** + * The event name for when an ad has started playing. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_STARTED = 'ad-started'; + + +/** + * The event name for when an ad playhead crosses first quartile. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_FIRST_QUARTILE = 'ad-first-quartile'; + + +/** + * The event name for when an ad playhead crosses midpoint. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_MIDPOINT = 'ad-midpoint'; + + +/** + * The event name for when an ad playhead crosses third quartile. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_THIRD_QUARTILE = 'ad-third-quartile'; + + +/** + * The event name for when an ad has completed playing. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_COMPLETE = 'ad-complete'; + + +/** + * The event name for when an ad has finished playing + * (played all the way through, was skipped, or was unable to proceed + * due to an error). + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_STOPPED = 'ad-stopped'; + + +/** + * The event name for when an ad is skipped by the user.. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_SKIPPED = 'ad-skipped'; + + +/** + * The event name for when the ad volume has changed. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_VOLUME_CHANGED = 'ad-volume-changed'; + + +/** + * The event name for when the ad was muted. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_MUTED = 'ad-muted'; + + +/** + * The event name for when the ad was paused. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_PAUSED = 'ad-paused'; + + +/** + * The event name for when the ad was resumed after a pause. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_RESUMED = 'ad-resumed'; + + +/** + * The event name for when the ad's skip status changes + * (usually it becomes skippable when it wasn't before). + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_SKIP_STATE_CHANGED = 'ad-skip-state-changed'; + + +/** + * The event name for when the ad's cue points (start/end markers) + * have changed. + * + * @const {string} + * @export + */ +shaka.ads.Utils.CUEPOINTS_CHANGED = 'ad-cue-points-changed'; + + +/** + * The event name for when the native IMA ad manager object has + * loaded and become available. + * + * @const {string} + * @export + */ +shaka.ads.Utils.IMA_AD_MANAGER_LOADED = 'ima-ad-manager-loaded'; + + +/** + * The event name for when the native IMA stream manager object has + * loaded and become available. + * + * @const {string} + * @export + */ +shaka.ads.Utils.IMA_STREAM_MANAGER_LOADED = 'ima-stream-manager-loaded'; + + +/** + * The event name for when the ad was clicked. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_CLICKED = 'ad-clicked'; + + +/** + * The event name for when there is an update to the current ad's progress. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_PROGRESS = 'ad-progress'; + + +/** + * The event name for when the ad is buffering. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_BUFFERING = 'ad-buffering'; + + +/** + * The event name for when the ad's URL was hit. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_IMPRESSION = 'ad-impression'; + + +/** + * The event name for when the ad's duration changed. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_DURATION_CHANGED = 'ad-duration-changed'; + + +/** + * The event name for when the ad was closed by the user. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_CLOSED = 'ad-closed'; + + +/** + * The event name for when the ad data becomes available. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_LOADED = 'ad-loaded'; + + +/** + * The event name for when all the ads were completed. + * + * @const {string} + * @export + */ +shaka.ads.Utils.ALL_ADS_COMPLETED = 'all-ads-completed'; + + +/** + * The event name for when the ad changes from or to linear. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_LINEAR_CHANGED = 'ad-linear-changed'; + + +/** + * The event name for when the ad's metadata becomes available. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_METADATA = 'ad-metadata'; + + +/** + * The event name for when the ad display encountered a recoverable + * error. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_RECOVERABLE_ERROR = 'ad-recoverable-error'; + +/** + * The event name for when the ad manager dispatch errors. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_ERROR = 'ad-error'; + +/** + * The event name for when the client side SDK signalled its readiness + * to play a VPAID ad or an ad rule. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_BREAK_READY = 'ad-break-ready'; + + +/** + * The event name for when the interaction callback for the ad was + * triggered. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_INTERACTION = 'ad-interaction'; + + +/** + * The name of the event for when an ad requires the main content to be paused. + * Fired when the platform does not support multiple media elements. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_CONTENT_PAUSE_REQUESTED = 'ad-content-pause-requested'; + + +/** + * The name of the event for when an ad requires the main content to be resumed. + * Fired when the platform does not support multiple media elements. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_CONTENT_RESUME_REQUESTED = 'ad-content-resume-requested'; + + +/** + * The name of the event for when an ad requires the video of the main content + * to be attached. + * + * @const {string} + * @export + */ +shaka.ads.Utils.AD_CONTENT_ATTACH_REQUESTED = 'ad-content-attach-requested'; + diff --git a/lib/ads/client_side_ad_manager.js b/lib/ads/client_side_ad_manager.js index 5b5479de44..9acff8cabd 100644 --- a/lib/ads/client_side_ad_manager.js +++ b/lib/ads/client_side_ad_manager.js @@ -4,15 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -/** - * @fileoverview - * @suppress {missingRequire} TODO(b/152540451): this shouldn't be needed - */ goog.provide('shaka.ads.ClientSideAdManager'); goog.require('goog.asserts'); +goog.require('shaka.Player'); goog.require('shaka.ads.ClientSideAd'); +goog.require('shaka.ads.Utils'); goog.require('shaka.log'); goog.require('shaka.util.Dom'); goog.require('shaka.util.EventManager'); @@ -190,12 +188,12 @@ shaka.ads.ClientSideAdManager = class { shaka.log.warning('Resuming playback.'); const data = (new Map()).set('originalEvent', e); - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.AD_ERROR, data)); + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.AD_ERROR, data)); this.onAdComplete_(/* adEvent= */ null); // Remove ad breaks from the timeline this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.CUEPOINTS_CHANGED, + new shaka.util.FakeEvent(shaka.ads.Utils.CUEPOINTS_CHANGED, (new Map()).set('cuepoints', []))); } @@ -209,7 +207,7 @@ shaka.ads.ClientSideAdManager = class { const now = Date.now() / 1000; const loadTime = now - this.requestAdsStartTime_; - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.ADS_LOADED, + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.ADS_LOADED, (new Map()).set('loadTime', loadTime))); if (!this.config_.customPlayheadTracker) { @@ -247,7 +245,7 @@ shaka.ads.ClientSideAdManager = class { } this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.IMA_AD_MANAGER_LOADED, + shaka.ads.Utils.IMA_AD_MANAGER_LOADED, (new Map()).set('imaAdManager', this.imaAdsManager_))); const cuePointStarts = this.imaAdsManager_.getCuePoints(); @@ -264,7 +262,7 @@ shaka.ads.ClientSideAdManager = class { } this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.CUEPOINTS_CHANGED, + shaka.ads.Utils.CUEPOINTS_CHANGED, (new Map()).set('cuepoints', cuePoints))); } @@ -374,22 +372,22 @@ shaka.ads.ClientSideAdManager = class { this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.FIRST_QUARTILE, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_FIRST_QUARTILE); + convertEventAndSend(e, shaka.ads.Utils.AD_FIRST_QUARTILE); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.MIDPOINT, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_MIDPOINT); + convertEventAndSend(e, shaka.ads.Utils.AD_MIDPOINT); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.THIRD_QUARTILE, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_THIRD_QUARTILE); + convertEventAndSend(e, shaka.ads.Utils.AD_THIRD_QUARTILE); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.COMPLETE, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_COMPLETE); + convertEventAndSend(e, shaka.ads.Utils.AD_COMPLETE); }); this.eventManager_.listen(this.imaAdsManager_, @@ -404,24 +402,24 @@ shaka.ads.ClientSideAdManager = class { this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.SKIPPED, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_SKIPPED); + convertEventAndSend(e, shaka.ads.Utils.AD_SKIPPED); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.VOLUME_CHANGED, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_VOLUME_CHANGED); + convertEventAndSend(e, shaka.ads.Utils.AD_VOLUME_CHANGED); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.VOLUME_MUTED, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_MUTED); + convertEventAndSend(e, shaka.ads.Utils.AD_MUTED); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.PAUSED, (e) => { if (this.ad_) { this.ad_.setPaused(true); - convertEventAndSend(e, shaka.ads.AdManager.AD_PAUSED); + convertEventAndSend(e, shaka.ads.Utils.AD_PAUSED); } }); @@ -429,80 +427,80 @@ shaka.ads.ClientSideAdManager = class { google.ima.AdEvent.Type.RESUMED, (e) => { if (this.ad_) { this.ad_.setPaused(false); - convertEventAndSend(e, shaka.ads.AdManager.AD_RESUMED); + convertEventAndSend(e, shaka.ads.Utils.AD_RESUMED); } }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.SKIPPABLE_STATE_CHANGED, (e) => { if (this.ad_) { - convertEventAndSend(e, shaka.ads.AdManager.AD_SKIP_STATE_CHANGED); + convertEventAndSend(e, shaka.ads.Utils.AD_SKIP_STATE_CHANGED); } }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.CLICK, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_CLICKED); + convertEventAndSend(e, shaka.ads.Utils.AD_CLICKED); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.AD_PROGRESS, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_PROGRESS); + convertEventAndSend(e, shaka.ads.Utils.AD_PROGRESS); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.AD_BUFFERING, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_BUFFERING); + convertEventAndSend(e, shaka.ads.Utils.AD_BUFFERING); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.IMPRESSION, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_IMPRESSION); + convertEventAndSend(e, shaka.ads.Utils.AD_IMPRESSION); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.DURATION_CHANGE, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_DURATION_CHANGED); + convertEventAndSend(e, shaka.ads.Utils.AD_DURATION_CHANGED); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.USER_CLOSE, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_CLOSED); + convertEventAndSend(e, shaka.ads.Utils.AD_CLOSED); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.LOADED, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_LOADED); + convertEventAndSend(e, shaka.ads.Utils.AD_LOADED); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.ALL_ADS_COMPLETED, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.ALL_ADS_COMPLETED); + convertEventAndSend(e, shaka.ads.Utils.ALL_ADS_COMPLETED); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.LINEAR_CHANGED, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_LINEAR_CHANGED); + convertEventAndSend(e, shaka.ads.Utils.AD_LINEAR_CHANGED); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.AD_METADATA, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_METADATA); + convertEventAndSend(e, shaka.ads.Utils.AD_METADATA); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.LOG, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_RECOVERABLE_ERROR); + convertEventAndSend(e, shaka.ads.Utils.AD_RECOVERABLE_ERROR); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.AD_BREAK_READY, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_BREAK_READY); + convertEventAndSend(e, shaka.ads.Utils.AD_BREAK_READY); }); this.eventManager_.listen(this.imaAdsManager_, google.ima.AdEvent.Type.INTERACTION, (e) => { - convertEventAndSend(e, shaka.ads.AdManager.AD_INTERACTION); + convertEventAndSend(e, shaka.ads.Utils.AD_INTERACTION); }); } @@ -530,14 +528,14 @@ shaka.ads.ClientSideAdManager = class { if (e.type == google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED && !this.config_.supportsMultipleMediaElements ) { this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.AD_CONTENT_PAUSE_REQUESTED)); + shaka.ads.Utils.AD_CONTENT_PAUSE_REQUESTED)); } const data = new Map() .set('ad', this.ad_) .set('sdkAdObject', imaAd) .set('originalEvent', e); this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.AD_STARTED, data)); + shaka.ads.Utils.AD_STARTED, data)); if (this.ad_.isLinear()) { this.adContainer_.setAttribute('ad-active', 'true'); if (!this.config_.customPlayheadTracker) { @@ -559,9 +557,9 @@ shaka.ads.ClientSideAdManager = class { if (e.type == google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED && !this.config_.supportsMultipleMediaElements) { this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.AD_CONTENT_RESUME_REQUESTED)); + shaka.ads.Utils.AD_CONTENT_RESUME_REQUESTED)); } - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STOPPED, + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.AD_STOPPED, (new Map()).set('originalEvent', e))); if (this.ad_ && this.ad_.isLinear()) { this.adContainer_.removeAttribute('ad-active'); diff --git a/lib/ads/interstitial_ad_manager.js b/lib/ads/interstitial_ad_manager.js index e41d01ad11..7cd34a16a9 100644 --- a/lib/ads/interstitial_ad_manager.js +++ b/lib/ads/interstitial_ad_manager.js @@ -4,23 +4,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -/** - * @fileoverview - * @suppress {missingRequire} TODO(b/152540451): this shouldn't be needed - */ goog.provide('shaka.ads.InterstitialAdManager'); goog.require('goog.asserts'); goog.require('shaka.Player'); goog.require('shaka.ads.InterstitialAd'); +goog.require('shaka.ads.Utils'); +goog.require('shaka.log'); goog.require('shaka.media.PreloadManager'); +goog.require('shaka.net.NetworkingEngine'); goog.require('shaka.util.Dom'); goog.require('shaka.util.EventManager'); goog.require('shaka.util.FakeEvent'); goog.require('shaka.util.IReleasable'); goog.require('shaka.util.Platform'); goog.require('shaka.util.PublicPromise'); +goog.require('shaka.util.StringUtils'); goog.require('shaka.util.Timer'); @@ -350,7 +350,7 @@ shaka.ads.InterstitialAdManager = class { if (this.usingBaseVideo_ && adPosition == 1) { this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.AD_CONTENT_PAUSE_REQUESTED, + shaka.ads.Utils.AD_CONTENT_PAUSE_REQUESTED, (new Map()).set('saveLivePosition', true))); const detachBasePlayerPromise = new shaka.util.PublicPromise(); const checkState = async (e) => { @@ -409,7 +409,7 @@ shaka.ads.InterstitialAdManager = class { interstitial.pre, adPosition - oncePlayed); if (nextCurrentInterstitial) { this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STOPPED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_STOPPED)); this.adEventManager_.removeAll(); this.setupAd_(nextCurrentInterstitial, sequenceLength, ++adPosition, initialTime, oncePlayed); @@ -429,11 +429,11 @@ shaka.ads.InterstitialAdManager = class { } } this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.AD_CONTENT_RESUME_REQUESTED, + shaka.ads.Utils.AD_CONTENT_RESUME_REQUESTED, (new Map()).set('offset', offset))); } this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STOPPED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_STOPPED)); this.adEventManager_.removeAll(); this.playingAd_ = false; if (!this.usingBaseVideo_) { @@ -449,7 +449,7 @@ shaka.ads.InterstitialAdManager = class { return; } unloadingInterstitial = true; - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.AD_ERROR, + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.AD_ERROR, (new Map()).set('originalEvent', e))); await basicTask(); }; @@ -460,14 +460,14 @@ shaka.ads.InterstitialAdManager = class { unloadingInterstitial = true; await basicTask(); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_COMPLETE)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_COMPLETE)); }; const onSkip = async () => { if (unloadingInterstitial) { return; } unloadingInterstitial = true; - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.AD_SKIPPED)); + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.AD_SKIPPED)); await basicTask(); }; @@ -479,45 +479,45 @@ shaka.ads.InterstitialAdManager = class { } this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STARTED, + new shaka.util.FakeEvent(shaka.ads.Utils.AD_STARTED, (new Map()).set('ad', ad))); if (ad.canSkipNow()) { this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.AD_SKIP_STATE_CHANGED)); + shaka.ads.Utils.AD_SKIP_STATE_CHANGED)); } this.adEventManager_.listenOnce(this.player_, 'error', error); this.adEventManager_.listenOnce(this.player_, 'firstquartile', () => { updateBaseVideoTime(); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_FIRST_QUARTILE)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_FIRST_QUARTILE)); }); this.adEventManager_.listenOnce(this.player_, 'midpoint', () => { updateBaseVideoTime(); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_MIDPOINT)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_MIDPOINT)); }); this.adEventManager_.listenOnce(this.player_, 'thirdquartile', () => { updateBaseVideoTime(); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_THIRD_QUARTILE)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_THIRD_QUARTILE)); }); this.adEventManager_.listenOnce(this.player_, 'complete', complete); this.adEventManager_.listen(this.video_, 'play', () => { this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_RESUMED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_RESUMED)); }); this.adEventManager_.listen(this.video_, 'pause', () => { this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_PAUSED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_PAUSED)); }); this.adEventManager_.listen(this.video_, 'volumechange', () => { if (this.video_.muted) { this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_MUTED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_MUTED)); } else { this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_VOLUME_CHANGED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_VOLUME_CHANGED)); } }); try { @@ -541,7 +541,7 @@ shaka.ads.InterstitialAdManager = class { await this.player_.load(interstitial.uri); } const loadTime = (Date.now() - startTime) / 1000; - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.ADS_LOADED, + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.ADS_LOADED, (new Map()).set('loadTime', loadTime))); if (this.usingBaseVideo_) { this.baseVideo_.play(); @@ -701,7 +701,7 @@ shaka.ads.InterstitialAdManager = class { } this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.CUEPOINTS_CHANGED, + shaka.ads.Utils.CUEPOINTS_CHANGED, (new Map()).set('cuepoints', cuePoints))); } diff --git a/lib/ads/media_tailor_ad_manager.js b/lib/ads/media_tailor_ad_manager.js index 6803aad451..4ceb4aed50 100755 --- a/lib/ads/media_tailor_ad_manager.js +++ b/lib/ads/media_tailor_ad_manager.js @@ -4,15 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -/** - * @fileoverview - * @suppress {missingRequire} TODO(b/152540451): this shouldn't be needed - */ goog.provide('shaka.ads.MediaTailorAdManager'); goog.require('goog.asserts'); goog.require('shaka.ads.MediaTailorAd'); +goog.require('shaka.ads.Utils'); goog.require('shaka.log'); goog.require('shaka.net.NetworkingEngine'); goog.require('goog.Uri'); @@ -135,7 +132,7 @@ shaka.ads.MediaTailorAdManager = class { */ addTrackingUrl(url) { this.trackingUrl_ = url; - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.ADS_LOADED, + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.ADS_LOADED, (new Map()).set('loadTime', 0))); } @@ -227,7 +224,7 @@ shaka.ads.MediaTailorAdManager = class { this.trackingUrl_ = baseUri.resolve(relativeTrackingUri).toString(); const now = Date.now() / 1000; const loadTime = now - this.streamRequestStartTime_; - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.ADS_LOADED, + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.ADS_LOADED, (new Map()).set('loadTime', loadTime))); const relativeManifestUri = new goog.Uri(dataAsJson.manifestUrl); this.streamPromise_.resolve( @@ -282,13 +279,13 @@ shaka.ads.MediaTailorAdManager = class { } cuepoints = this.getCuePoints(); this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.CUEPOINTS_CHANGED, + shaka.ads.Utils.CUEPOINTS_CHANGED, (new Map()).set('cuepoints', cuepoints))); } } else { if (this.adBreaks_.length) { this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.CUEPOINTS_CHANGED, + shaka.ads.Utils.CUEPOINTS_CHANGED, (new Map()).set('cuepoints', cuepoints))); } this.onEnded_(); @@ -727,52 +724,52 @@ shaka.ads.MediaTailorAdManager = class { switch (eventType) { case shaka.ads.MediaTailorAdManager.IMPRESSION_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_IMPRESSION)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_IMPRESSION)); break; case shaka.ads.MediaTailorAdManager.START_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STARTED, + new shaka.util.FakeEvent(shaka.ads.Utils.AD_STARTED, (new Map()).set('ad', this.ad_))); break; case shaka.ads.MediaTailorAdManager.MUTE_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_MUTED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_MUTED)); break; case shaka.ads.MediaTailorAdManager.UNMUTE_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_VOLUME_CHANGED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_VOLUME_CHANGED)); break; case shaka.ads.MediaTailorAdManager.RESUME_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_RESUMED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_RESUMED)); break; case shaka.ads.MediaTailorAdManager.PAUSE_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_PAUSED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_PAUSED)); break; case shaka.ads.MediaTailorAdManager.FIRSTQUARTILE_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_FIRST_QUARTILE)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_FIRST_QUARTILE)); break; case shaka.ads.MediaTailorAdManager.MIDPOINT_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_MIDPOINT)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_MIDPOINT)); break; case shaka.ads.MediaTailorAdManager.THIRDQUARTILE_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_THIRD_QUARTILE)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_THIRD_QUARTILE)); break; case shaka.ads.MediaTailorAdManager.COMPLETE_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_COMPLETE)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_COMPLETE)); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STOPPED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_STOPPED)); break; case shaka.ads.MediaTailorAdManager.SKIPPED_: this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_SKIPPED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_SKIPPED)); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STOPPED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_STOPPED)); break; case shaka.ads.MediaTailorAdManager.BREAKSTART_: this.adContainer_.setAttribute('ad-active', 'true'); @@ -783,7 +780,7 @@ shaka.ads.MediaTailorAdManager = class { case shaka.ads.MediaTailorAdManager.SKIP_STATE_CHANGED_: this.onEvent_( new shaka.util.FakeEvent( - shaka.ads.AdManager.AD_SKIP_STATE_CHANGED)); + shaka.ads.Utils.AD_SKIP_STATE_CHANGED)); break; } } diff --git a/lib/ads/server_side_ad_manager.js b/lib/ads/server_side_ad_manager.js index 43d5f91e25..55e5a06df4 100644 --- a/lib/ads/server_side_ad_manager.js +++ b/lib/ads/server_side_ad_manager.js @@ -4,14 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -/** - * @fileoverview - * @suppress {missingRequire} TODO(b/152540451): this shouldn't be needed - */ goog.provide('shaka.ads.ServerSideAdManager'); goog.require('goog.asserts'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ads.ServerSideAd'); goog.require('shaka.log'); goog.require('shaka.util.EventManager'); @@ -86,7 +83,7 @@ shaka.ads.ServerSideAdManager = class { this.video_, this.adContainer_, uiSettings); this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.IMA_STREAM_MANAGER_LOADED, + shaka.ads.Utils.IMA_STREAM_MANAGER_LOADED, (new Map()).set('imaStreamManager', this.streamManager_))); // Events @@ -130,30 +127,30 @@ shaka.ads.ServerSideAdManager = class { google.ima.dai.api.StreamEvent.Type.FIRST_QUARTILE, () => { shaka.log.info('Ad event: First Quartile'); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_FIRST_QUARTILE)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_FIRST_QUARTILE)); }); this.eventManager_.listen(this.streamManager_, google.ima.dai.api.StreamEvent.Type.MIDPOINT, () => { shaka.log.info('Ad event: Midpoint'); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_MIDPOINT)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_MIDPOINT)); }); this.eventManager_.listen(this.streamManager_, google.ima.dai.api.StreamEvent.Type.THIRD_QUARTILE, () => { shaka.log.info('Ad event: Third Quartile'); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_THIRD_QUARTILE)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_THIRD_QUARTILE)); }); this.eventManager_.listen(this.streamManager_, google.ima.dai.api.StreamEvent.Type.COMPLETE, () => { shaka.log.info('Ad event: Complete'); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_COMPLETE)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_COMPLETE)); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STOPPED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_STOPPED)); this.adContainer_.removeAttribute('ad-active'); this.ad_ = null; }); @@ -162,9 +159,9 @@ shaka.ads.ServerSideAdManager = class { google.ima.dai.api.StreamEvent.Type.SKIPPED, () => { shaka.log.info('Ad event: Skipped'); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_SKIPPED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_SKIPPED)); this.onEvent_( - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STOPPED)); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_STOPPED)); }); this.eventManager_.listen(this.streamManager_, @@ -323,7 +320,7 @@ shaka.ads.ServerSideAdManager = class { this.ad_.setProgressData(this.adProgressData_); } - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STARTED, + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.AD_STARTED, (new Map()).set('ad', this.ad_))); this.adContainer_.setAttribute('ad-active', 'true'); } @@ -350,7 +347,7 @@ shaka.ads.ServerSideAdManager = class { onLoaded_(e) { const now = Date.now() / 1000; const loadTime = now - this.streamRequestStartTime_; - this.onEvent_(new shaka.util.FakeEvent(shaka.ads.AdManager.ADS_LOADED, + this.onEvent_(new shaka.util.FakeEvent(shaka.ads.Utils.ADS_LOADED, (new Map()).set('loadTime', loadTime))); const streamData = e.getStreamData(); @@ -418,7 +415,7 @@ shaka.ads.ServerSideAdManager = class { this.currentCuePoints_ = cuePoints; this.onEvent_(new shaka.util.FakeEvent( - shaka.ads.AdManager.CUEPOINTS_CHANGED, + shaka.ads.Utils.CUEPOINTS_CHANGED, (new Map()).set('cuepoints', cuePoints))); } }; diff --git a/lib/player.js b/lib/player.js index 5a3769e92c..d907c512e1 100644 --- a/lib/player.js +++ b/lib/player.js @@ -800,7 +800,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget { this.adManager_ = shaka.Player.adManagerFactory_(); this.adManager_.configure(this.config_.ads); - // Note: we don't use shaka.ads.AdManager.AD_CONTENT_PAUSE_REQUESTED to + // Note: we don't use shaka.ads.Utils.AD_CONTENT_PAUSE_REQUESTED to // avoid add a optional module in the player. this.adManagerEventManager_.listen( this.adManager_, 'ad-content-pause-requested', async (e) => { @@ -815,7 +815,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget { } }); - // Note: we don't use shaka.ads.AdManager.AD_CONTENT_RESUME_REQUESTED to + // Note: we don't use shaka.ads.Utils.AD_CONTENT_RESUME_REQUESTED to // avoid add a optional module in the player. this.adManagerEventManager_.listen( this.adManager_, 'ad-content-resume-requested', (e) => { @@ -826,7 +826,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget { this.preloadDueAdManagerTimer_.tickAfter(0.1); }); - // Note: we don't use shaka.ads.AdManager.AD_CONTENT_ATTACH_REQUESTED to + // Note: we don't use shaka.ads.Utils.AD_CONTENT_ATTACH_REQUESTED to // avoid add a optional module in the player. this.adManagerEventManager_.listen( this.adManager_, 'ad-content-attach-requested', async (e) => { diff --git a/test/ads/ad_manager_unit.js b/test/ads/ad_manager_unit.js index 7462730208..95f398156c 100644 --- a/test/ads/ad_manager_unit.js +++ b/test/ads/ad_manager_unit.js @@ -152,11 +152,11 @@ describe('Ad manager', () => { const eventManager = new shaka.util.EventManager(); let loaded = false; let numAdStarted = 0; - const AdManager = shaka.ads.AdManager; - eventManager.listen(adManager, AdManager.IMA_AD_MANAGER_LOADED, () => { - loaded = true; - }); - eventManager.listen(adManager, AdManager.AD_STARTED, () => { + eventManager.listen(adManager, + shaka.ads.Utils.IMA_AD_MANAGER_LOADED, () => { + loaded = true; + }); + eventManager.listen(adManager, shaka.ads.Utils.AD_STARTED, () => { numAdStarted += 1; }); diff --git a/test/ads_integration.js b/test/ads_integration.js index 0cb7be9283..b845997272 100644 --- a/test/ads_integration.js +++ b/test/ads_integration.js @@ -61,7 +61,7 @@ describe('Ads', () => { fail(event.detail); }); eventManager.listen(player, 'error', Util.spyFunc(onErrorSpy)); - eventManager.listen(adManager, shaka.ads.AdManager.AD_ERROR, + eventManager.listen(adManager, shaka.ads.Utils.AD_ERROR, Util.spyFunc(onErrorSpy)); }); @@ -115,15 +115,15 @@ describe('Ads', () => { // Wait a maximum of 10 seconds before the ad starts playing. await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_FIRST_QUARTILE); + .waitForEvent(adManager, shaka.ads.Utils.AD_FIRST_QUARTILE); await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_MIDPOINT); + .waitForEvent(adManager, shaka.ads.Utils.AD_MIDPOINT); await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_THIRD_QUARTILE); + .waitForEvent(adManager, shaka.ads.Utils.AD_THIRD_QUARTILE); await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); // Play for 10 seconds, but stop early if the video ends. If it takes // longer than 30 seconds, fail the test. @@ -158,15 +158,15 @@ describe('Ads', () => { // Wait a maximum of 10 seconds before the ad starts playing. await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_FIRST_QUARTILE); + .waitForEvent(adManager, shaka.ads.Utils.AD_FIRST_QUARTILE); await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_MIDPOINT); + .waitForEvent(adManager, shaka.ads.Utils.AD_MIDPOINT); await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_THIRD_QUARTILE); + .waitForEvent(adManager, shaka.ads.Utils.AD_THIRD_QUARTILE); await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); // Play for 10 seconds, but stop early if the video ends. If it takes // longer than 30 seconds, fail the test. @@ -194,18 +194,18 @@ describe('Ads', () => { // Wait a maximum of 10 seconds before the ad starts playing. await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); await waiter.timeoutAfter(20) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); await shaka.test.Util.delay(1); expect(video.currentTime).toBeLessThanOrEqual(3); // Wait a maximum of 10 seconds before the ad starts playing. await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); await waiter.timeoutAfter(20) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); await shaka.test.Util.delay(1); expect(video.currentTime).toBeGreaterThan(8); @@ -228,18 +228,18 @@ describe('Ads', () => { // Wait a maximum of 10 seconds before the ad starts playing. await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); await waiter.timeoutAfter(20) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); await shaka.test.Util.delay(1); expect(video.currentTime).toBeLessThanOrEqual(3); // Wait a maximum of 10 seconds before the ad starts playing. await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); await waiter.timeoutAfter(20) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); await shaka.test.Util.delay(1); expect(video.currentTime).toBeGreaterThan(8); @@ -260,18 +260,18 @@ describe('Ads', () => { // Wait a maximum of 10 seconds before the ad starts playing. await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); await waiter.timeoutAfter(20) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); await shaka.test.Util.delay(1); expect(video.currentTime).toBeLessThanOrEqual(3); // Wait a maximum of 10 seconds before the ad starts playing. await waiter.timeoutAfter(10) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); await waiter.timeoutAfter(20) - .waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + .waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); // Play for 10 seconds, but stop early if the video ends. If it takes // longer than 30 seconds, fail the test. diff --git a/test/test/util/fake_ad_manager.js b/test/test/util/fake_ad_manager.js index 885bc73dd9..b8db2fe43f 100644 --- a/test/test/util/fake_ad_manager.js +++ b/test/test/util/fake_ad_manager.js @@ -98,7 +98,7 @@ shaka.test.FakeAdManager = class extends shaka.util.FakeEventTarget { * @param {!shaka.test.FakeAd} ad */ startAd(ad) { - const event = new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STARTED, + const event = new shaka.util.FakeEvent(shaka.ads.Utils.AD_STARTED, (new Map()).set('ad', ad)); this.dispatchEvent(event); @@ -106,14 +106,14 @@ shaka.test.FakeAdManager = class extends shaka.util.FakeEventTarget { /** @public */ finishAd() { - const event = new shaka.util.FakeEvent(shaka.ads.AdManager.AD_STOPPED); + const event = new shaka.util.FakeEvent(shaka.ads.Utils.AD_STOPPED); this.dispatchEvent(event); } /** @public */ changeSkipState() { const event = - new shaka.util.FakeEvent(shaka.ads.AdManager.AD_SKIP_STATE_CHANGED); + new shaka.util.FakeEvent(shaka.ads.Utils.AD_SKIP_STATE_CHANGED); this.dispatchEvent(event); } }; diff --git a/test/ui/ad_ui_unit.js b/test/ui/ad_ui_unit.js index 9c8ef387fb..0d117f8b0e 100644 --- a/test/ui/ad_ui_unit.js +++ b/test/ui/ad_ui_unit.js @@ -54,7 +54,7 @@ describe('Ad UI', () => { it('becomes visible if an ad is playing', async () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); - const p = waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + const p = waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); ad = new shaka.test.FakeAd(/* skipIn= */ null, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -72,10 +72,10 @@ describe('Ad UI', () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); const pStart = - waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); const pStop = - waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); ad = new shaka.test.FakeAd(/* skipIn= */ null, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -107,7 +107,7 @@ describe('Ad UI', () => { it('is invisible if an unskippable ad is playing', async () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); - const p = waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + const p = waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); ad = new shaka.test.FakeAd(/* skipIn= */ null, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -121,7 +121,7 @@ describe('Ad UI', () => { it('becomes visible if a skippable ad is playing', async () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); - const p = waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + const p = waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); ad = new shaka.test.FakeAd(/* skipIn= */ 10, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -135,7 +135,7 @@ describe('Ad UI', () => { it('correctly shows the time until the ad can be skipped', async () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); - const p = waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + const p = waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); ad = new shaka.test.FakeAd(/* skipIn= */ 10, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -152,7 +152,7 @@ describe('Ad UI', () => { it('is disabled if skip count is greater than 0', async () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); - const p = waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + const p = waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); ad = new shaka.test.FakeAd(/* skipIn= */ 10, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -167,9 +167,9 @@ describe('Ad UI', () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); const pStart = - waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); const pSkip = waiter.waitForEvent( - adManager, shaka.ads.AdManager.AD_SKIP_STATE_CHANGED); + adManager, shaka.ads.Utils.AD_SKIP_STATE_CHANGED); ad = new shaka.test.FakeAd(/* skipIn= */ 0, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -186,9 +186,9 @@ describe('Ad UI', () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); const pStart = - waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); const pSkip = waiter.waitForEvent( - adManager, shaka.ads.AdManager.AD_SKIP_STATE_CHANGED); + adManager, shaka.ads.Utils.AD_SKIP_STATE_CHANGED); ad = new shaka.test.FakeAd(/* skipIn= */ 10, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -224,7 +224,7 @@ describe('Ad UI', () => { it('displays correct ad time', async () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); - const p = waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + const p = waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); ad = new shaka.test.FakeAd(/* skipIn= */ null, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -267,7 +267,7 @@ describe('Ad UI', () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); const p = waiter.waitForEvent( - adManager, shaka.ads.AdManager.AD_STARTED); + adManager, shaka.ads.Utils.AD_STARTED); ad = new shaka.test.FakeAd(/* skipIn= */ null, /* position= */ position, /* totalAdsInPod= */ adsInPod); @@ -301,7 +301,7 @@ describe('Ad UI', () => { it('dissappears when an ad is playing', async () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); - const p = waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + const p = waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); ad = new shaka.test.FakeAd(/* skipIn= */ null, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -329,7 +329,7 @@ describe('Ad UI', () => { it('is hidden when an ad is playing', async () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); - const p = waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + const p = waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); ad = new shaka.test.FakeAd(/* skipIn= */ null, /* position= */ 1, /* totalAdsInPod= */ 1); @@ -344,10 +344,10 @@ describe('Ad UI', () => { const eventManager = new shaka.util.EventManager(); const waiter = new shaka.test.Waiter(eventManager); const pStart = - waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STARTED); + waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STARTED); const pStop = - waiter.waitForEvent(adManager, shaka.ads.AdManager.AD_STOPPED); + waiter.waitForEvent(adManager, shaka.ads.Utils.AD_STOPPED); ad = new shaka.test.FakeAd(/* skipIn= */ null, /* position= */ 1, /* totalAdsInPod= */ 1); diff --git a/ui/ad_counter.js b/ui/ad_counter.js index 2717b895b0..1427147eb8 100644 --- a/ui/ad_counter.js +++ b/ui/ad_counter.js @@ -8,7 +8,7 @@ goog.provide('shaka.ui.AdCounter'); goog.require('goog.asserts'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ui.Element'); goog.require('shaka.ui.Locales'); goog.require('shaka.ui.Localization'); @@ -63,12 +63,12 @@ shaka.ui.AdCounter = class extends shaka.ui.Element { }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STARTED, () => { + this.adManager, shaka.ads.Utils.AD_STARTED, () => { this.onAdStarted_(); }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STOPPED, () => { + this.adManager, shaka.ads.Utils.AD_STOPPED, () => { this.reset_(); }); diff --git a/ui/ad_position.js b/ui/ad_position.js index 2bf414e66f..49dc2170d1 100644 --- a/ui/ad_position.js +++ b/ui/ad_position.js @@ -7,7 +7,7 @@ goog.provide('shaka.ui.AdPosition'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ui.Element'); goog.require('shaka.ui.Locales'); goog.require('shaka.ui.Localization'); @@ -63,12 +63,12 @@ shaka.ui.AdPosition = class extends shaka.ui.Element { }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STARTED, () => { + this.adManager, shaka.ads.Utils.AD_STARTED, () => { this.setPosition_(); }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STOPPED, () => { + this.adManager, shaka.ads.Utils.AD_STOPPED, () => { this.span_.textContent = ''; shaka.ui.Utils.setDisplay(this.container_, false); }); diff --git a/ui/ad_statistics_button.js b/ui/ad_statistics_button.js index aecd9c6575..53e0b33a6a 100644 --- a/ui/ad_statistics_button.js +++ b/ui/ad_statistics_button.js @@ -8,7 +8,7 @@ goog.provide('shaka.ui.AdStatisticsButton'); goog.require('shaka.log'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ui.ContextMenu'); goog.require('shaka.ui.Controls'); goog.require('shaka.ui.Element'); @@ -134,7 +134,7 @@ shaka.ui.AdStatisticsButton = class extends shaka.ui.Element { }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STARTED, () => { + this.adManager, shaka.ads.Utils.AD_STARTED, () => { shaka.ui.Utils.setDisplay(this.button_, true); }); } diff --git a/ui/controls.js b/ui/controls.js index 9bae715ee5..024c47528e 100644 --- a/ui/controls.js +++ b/ui/controls.js @@ -9,7 +9,7 @@ goog.provide('shaka.ui.Controls'); goog.provide('shaka.ui.ControlsPanel'); goog.require('goog.asserts'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.cast.CastProxy'); goog.require('shaka.log'); goog.require('shaka.ui.AdCounter'); @@ -1216,13 +1216,13 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget { }); this.eventManager_.listen( - this.adManager_, shaka.ads.AdManager.AD_STARTED, (e) => { + this.adManager_, shaka.ads.Utils.AD_STARTED, (e) => { this.ad_ = (/** @type {!Object} */ (e))['ad']; this.showAdUI(); }); this.eventManager_.listen( - this.adManager_, shaka.ads.AdManager.AD_STOPPED, () => { + this.adManager_, shaka.ads.Utils.AD_STOPPED, () => { this.ad_ = null; this.hideAdUI(); }); diff --git a/ui/element.js b/ui/element.js index 0910e125d8..db73d137fe 100644 --- a/ui/element.js +++ b/ui/element.js @@ -7,7 +7,7 @@ goog.provide('shaka.ui.Element'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.util.EventManager'); goog.requireType('shaka.Player'); goog.requireType('shaka.ui.Controls'); @@ -73,12 +73,12 @@ shaka.ui.Element = class { */ this.ad = controls.getAd(); - const AD_STARTED = shaka.ads.AdManager.AD_STARTED; + const AD_STARTED = shaka.ads.Utils.AD_STARTED; this.eventManager.listen(this.adManager, AD_STARTED, (e) => { this.ad = (/** @type {!Object} */ (e))['ad']; }); - const AD_STOPPED = shaka.ads.AdManager.AD_STOPPED; + const AD_STOPPED = shaka.ads.Utils.AD_STOPPED; this.eventManager.listen(this.adManager, AD_STOPPED, () => { this.ad = null; }); diff --git a/ui/mute_button.js b/ui/mute_button.js index ea85b3f978..29f26d7fa0 100644 --- a/ui/mute_button.js +++ b/ui/mute_button.js @@ -7,7 +7,7 @@ goog.provide('shaka.ui.MuteButton'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ui.Controls'); goog.require('shaka.ui.Element'); goog.require('shaka.ui.Enums'); @@ -62,19 +62,19 @@ shaka.ui.MuteButton = class extends shaka.ui.Element { }); this.eventManager.listen(this.adManager, - shaka.ads.AdManager.AD_VOLUME_CHANGED, () => { + shaka.ads.Utils.AD_VOLUME_CHANGED, () => { this.updateAriaLabel_(); this.updateIcon_(); }); this.eventManager.listen(this.adManager, - shaka.ads.AdManager.AD_MUTED, () => { + shaka.ads.Utils.AD_MUTED, () => { this.updateAriaLabel_(); this.updateIcon_(); }); this.eventManager.listen(this.adManager, - shaka.ads.AdManager.AD_STOPPED, () => { + shaka.ads.Utils.AD_STOPPED, () => { // The base class also listens for this event and sets this.ad // to null. This is a safeguard in case of a race condition as // the label and icon code depends on this.ad being correctly diff --git a/ui/overflow_menu.js b/ui/overflow_menu.js index e0d2a41574..cb0f575223 100644 --- a/ui/overflow_menu.js +++ b/ui/overflow_menu.js @@ -8,7 +8,7 @@ goog.provide('shaka.ui.OverflowMenu'); goog.require('goog.asserts'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.log'); goog.require('shaka.ui.Controls'); goog.require('shaka.ui.Element'); @@ -59,14 +59,14 @@ shaka.ui.OverflowMenu = class extends shaka.ui.Element { }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STARTED, () => { + this.adManager, shaka.ads.Utils.AD_STARTED, () => { if (this.ad && this.ad.isLinear()) { shaka.ui.Utils.setDisplay(this.overflowMenuButton_, false); } }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STOPPED, () => { + this.adManager, shaka.ads.Utils.AD_STOPPED, () => { shaka.ui.Utils.setDisplay(this.overflowMenuButton_, true); }); diff --git a/ui/play_button.js b/ui/play_button.js index 06da7d681a..5eea9b4099 100644 --- a/ui/play_button.js +++ b/ui/play_button.js @@ -7,7 +7,7 @@ goog.provide('shaka.ui.PlayButton'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ui.Element'); goog.require('shaka.ui.Localization'); goog.require('shaka.util.Dom'); @@ -27,8 +27,6 @@ shaka.ui.PlayButton = class extends shaka.ui.Element { constructor(parent, controls) { super(parent, controls); - const AdManager = shaka.ads.AdManager; - /** @protected {!HTMLButtonElement} */ this.button = shaka.util.Dom.createButton(); this.parent.appendChild(this.button); @@ -58,22 +56,22 @@ shaka.ui.PlayButton = class extends shaka.ui.Element { this.updateIcon(); }); - this.eventManager.listen(this.adManager, AdManager.AD_PAUSED, () => { + this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_PAUSED, () => { this.updateAriaLabel(); this.updateIcon(); }); - this.eventManager.listen(this.adManager, AdManager.AD_RESUMED, () => { + this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_RESUMED, () => { this.updateAriaLabel(); this.updateIcon(); }); - this.eventManager.listen(this.adManager, AdManager.AD_STARTED, () => { + this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_STARTED, () => { this.updateAriaLabel(); this.updateIcon(); }); - this.eventManager.listen(this.adManager, AdManager.AD_STOPPED, () => { + this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_STOPPED, () => { this.updateAriaLabel(); this.updateIcon(); }); diff --git a/ui/presentation_time.js b/ui/presentation_time.js index eb82019514..8f5b3ec012 100644 --- a/ui/presentation_time.js +++ b/ui/presentation_time.js @@ -7,7 +7,7 @@ goog.provide('shaka.ui.PresentationTimeTracker'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ui.Controls'); goog.require('shaka.ui.Element'); goog.require('shaka.ui.Locales'); @@ -54,12 +54,12 @@ shaka.ui.PresentationTimeTracker = class extends shaka.ui.Element { }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STARTED, () => { + this.adManager, shaka.ads.Utils.AD_STARTED, () => { shaka.ui.Utils.setDisplay(this.currentTime_, false); }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STOPPED, () => { + this.adManager, shaka.ads.Utils.AD_STOPPED, () => { shaka.ui.Utils.setDisplay(this.currentTime_, true); }); } diff --git a/ui/seek_bar.js b/ui/seek_bar.js index 036e5c0210..9b66a329d3 100644 --- a/ui/seek_bar.js +++ b/ui/seek_bar.js @@ -7,7 +7,7 @@ goog.provide('shaka.ui.SeekBar'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.net.NetworkingEngine'); goog.require('shaka.ui.Constants'); goog.require('shaka.ui.Locales'); @@ -151,21 +151,21 @@ shaka.ui.SeekBar = class extends shaka.ui.RangeElement { () => this.updateAriaLabel_()); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STARTED, () => { + this.adManager, shaka.ads.Utils.AD_STARTED, () => { if (!this.shouldBeDisplayed_()) { shaka.ui.Utils.setDisplay(this.container, false); } }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STOPPED, () => { + this.adManager, shaka.ads.Utils.AD_STOPPED, () => { if (this.shouldBeDisplayed_()) { shaka.ui.Utils.setDisplay(this.container, true); } }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.CUEPOINTS_CHANGED, (e) => { + this.adManager, shaka.ads.Utils.CUEPOINTS_CHANGED, (e) => { this.adCuePoints_ = (e)['cuepoints']; this.onAdCuePointsChanged_(); }); diff --git a/ui/skip_ad_button.js b/ui/skip_ad_button.js index c411203a16..595ab358eb 100644 --- a/ui/skip_ad_button.js +++ b/ui/skip_ad_button.js @@ -8,7 +8,7 @@ goog.provide('shaka.ui.SkipAdButton'); goog.require('goog.asserts'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ui.Element'); goog.require('shaka.ui.Locales'); goog.require('shaka.ui.Localization'); @@ -74,17 +74,17 @@ shaka.ui.SkipAdButton = class extends shaka.ui.Element { }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STARTED, () => { + this.adManager, shaka.ads.Utils.AD_STARTED, () => { this.onAdStarted_(); }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_SKIP_STATE_CHANGED, () => { + this.adManager, shaka.ads.Utils.AD_SKIP_STATE_CHANGED, () => { this.onSkipStateChanged_(); }); this.eventManager.listen( - this.adManager, shaka.ads.AdManager.AD_STOPPED, () => { + this.adManager, shaka.ads.Utils.AD_STOPPED, () => { this.reset_(); }); diff --git a/ui/volume_bar.js b/ui/volume_bar.js index 822e14a055..839cfde24d 100644 --- a/ui/volume_bar.js +++ b/ui/volume_bar.js @@ -8,7 +8,7 @@ goog.provide('shaka.ui.VolumeBar'); goog.require('goog.asserts'); -goog.require('shaka.ads.AdManager'); +goog.require('shaka.ads.Utils'); goog.require('shaka.ui.Controls'); goog.require('shaka.ui.Locales'); goog.require('shaka.ui.Localization'); @@ -41,15 +41,15 @@ shaka.ui.VolumeBar = class extends shaka.ui.RangeElement { () => this.onPresentationVolumeChange_()); this.eventManager.listen(this.adManager, - shaka.ads.AdManager.AD_VOLUME_CHANGED, + shaka.ads.Utils.AD_VOLUME_CHANGED, () => this.onAdVolumeChange_()); this.eventManager.listen(this.adManager, - shaka.ads.AdManager.AD_MUTED, + shaka.ads.Utils.AD_MUTED, () => this.onAdVolumeChange_()); this.eventManager.listen(this.adManager, - shaka.ads.AdManager.AD_STOPPED, + shaka.ads.Utils.AD_STOPPED, () => this.onPresentationVolumeChange_()); this.eventManager.listen(this.localization,