From 673b7fceedaea659a8c5e9890fd8434d974756f1 Mon Sep 17 00:00:00 2001 From: Simon Gingras Date: Thu, 2 Mar 2023 01:14:27 -0500 Subject: [PATCH] feat(ads): Dispatch a player event for client-side ad errors (#5045) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes https://github.com/shaka-project/shaka-player/issues/4335 The errors are now forwarded to the player --------- Co-authored-by: Álvaro Velad Galván --- lib/ads/ad_manager.js | 18 ++++++++++++++++++ lib/ads/client_side_ad_manager.js | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/lib/ads/ad_manager.js b/lib/ads/ad_manager.js index 920ac303df..b0742b1ef9 100644 --- a/lib/ads/ad_manager.js +++ b/lib/ads/ad_manager.js @@ -314,6 +314,17 @@ goog.require('shaka.util.IReleasable'); */ +/** + * @event shaka.ads.AdManager.AD_ERROR + * @description Fired when a fatal error is encountered. + * @property {string} type + * 'ad-error' + * @property {Object} originalEvent + * The native SDK event, if available. + * @exportDoc + */ + + /** * @event shaka.ads.AdManager.AdInteractionEvent * @description Fired when an ad triggers the interaction callback. @@ -902,6 +913,13 @@ shaka.ads.AdManager.AD_METADATA = 'ad-metadata'; */ shaka.ads.AdManager.AD_RECOVERABLE_ERROR = 'ad-recoverable-error'; +/** + * The event name for when the ad manager dispatch errors. + * + * @const {string} + * @export + */ +shaka.ads.AdManager.AD_ERROR = 'ad-error'; /** * The event name for when the client side SDK signalled its readiness diff --git a/lib/ads/client_side_ad_manager.js b/lib/ads/client_side_ad_manager.js index 2a35e2c5b8..718acc0e63 100644 --- a/lib/ads/client_side_ad_manager.js +++ b/lib/ads/client_side_ad_manager.js @@ -133,6 +133,10 @@ shaka.ads.ClientSideAdManager = class { shaka.log.warning( 'There was an ad error from the IMA SDK: ' + e.getError()); 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.onAdComplete_(/* adEvent= */ null); // Remove ad breaks from the timeline this.onEvent_(