diff --git a/lib/util/fake_event_target.js b/lib/util/fake_event_target.js index f0a26f9ed6..7412edef44 100644 --- a/lib/util/fake_event_target.js +++ b/lib/util/fake_event_target.js @@ -49,6 +49,18 @@ shaka.util.FakeEventTarget = class { this.listeners_.push(type, listener); } + /** + * Add an event listener to this object that is invoked for all events types + * the object fires. + * + * @param {shaka.util.FakeEventTarget.ListenerType} listener The callback or + * listener object to invoke. + * @exportInterface + */ + listenToAllEvents(listener) { + this.addEventListener(shaka.util.FakeEventTarget.ALL_EVENTS_, listener); + } + /** * Remove an event listener from this object. * @@ -78,7 +90,12 @@ shaka.util.FakeEventTarget = class { goog.asserts.assert(event instanceof shaka.util.FakeEvent, 'FakeEventTarget can only dispatch FakeEvents!'); - const listeners = this.listeners_.get(event.type) || []; + let listeners = this.listeners_.get(event.type) || []; + const universalListeners = + this.listeners_.get(shaka.util.FakeEventTarget.ALL_EVENTS_); + if (universalListeners) { + listeners = listeners.concat(universalListeners); + } // Execute this event on listeners until the event has been stopped or we // run out of listeners. @@ -120,3 +137,10 @@ shaka.util.FakeEventTarget = class { * @exportInterface */ shaka.util.FakeEventTarget.ListenerType; + + +/** + * @const {string} + * @private + */ +shaka.util.FakeEventTarget.ALL_EVENTS_ = 'All';