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: Put custom event definitions in class #7640

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 2 additions & 0 deletions build/types/core
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
+../../lib/deprecate/enforcer.js
+../../lib/deprecate/version.js

+../../lib/event/error_event.js

+../../lib/media/adaptation_set.js
+../../lib/media/adaptation_set_criteria.js
+../../lib/media/buffering_observer.js
Expand Down
2 changes: 1 addition & 1 deletion demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ shakaDemo.Main = class {
*/
onErrorEvent_(event) {
// TODO: generate externs automatically from @event types
// This event should be shaka.Player.ErrorEvent
// This event should be shaka.events.ErrorEvent
this.onError_(event['detail']);
}

Expand Down
5 changes: 2 additions & 3 deletions lib/cast/cast_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ goog.require('shaka.Player');
goog.require('shaka.cast.CastSender');
goog.require('shaka.cast.CastUtils');
goog.require('shaka.log');
goog.require('shaka.events.ErrorEvent');
goog.require('shaka.util.Error');
goog.require('shaka.util.EventManager');
goog.require('shaka.util.FakeEvent');
Expand Down Expand Up @@ -553,9 +554,7 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
// Pass any errors through to the app.
goog.asserts.assert(error instanceof shaka.util.Error,
'Wrong error type!');
const eventType = shaka.util.FakeEvent.EventName.Error;
const data = (new Map()).set('detail', error);
const event = new shaka.util.FakeEvent(eventType, data);
const event = new shaka.events.ErrorEvent(error);
this.localPlayer_.dispatchEvent(event);
});
}
Expand Down
5 changes: 2 additions & 3 deletions lib/cast/cast_receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ goog.require('goog.asserts');
goog.require('shaka.Player');
goog.require('shaka.cast.CastUtils');
goog.require('shaka.log');
goog.require('shaka.events.ErrorEvent');
goog.require('shaka.util.Error');
goog.require('shaka.util.EventManager');
goog.require('shaka.util.FakeEvent');
Expand Down Expand Up @@ -395,9 +396,7 @@ shaka.cast.CastReceiver = class extends shaka.util.FakeEventTarget {
// Pass any errors through to the app.
goog.asserts.assert(error instanceof shaka.util.Error,
'Wrong error type! Error: ' + error);
const eventType = shaka.util.FakeEvent.EventName.Error;
const data = (new Map()).set('detail', error);
const event = new shaka.util.FakeEvent(eventType, data);
const event = new shaka.events.ErrorEvent(error);
// Only dispatch the event if the player still exists.
if (this.player_) {
this.player_.dispatchEvent(event);
Expand Down
39 changes: 39 additions & 0 deletions lib/event/error_event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

goog.provide('shaka.events.ErrorEvent');

goog.require('shaka.util.Error');
goog.require('shaka.util.FakeEvent');


/**
* @event shaka.events.ErrorEvent
* @description Fired when a playback error occurs.
* @property {string} type
* 'error'
* @property {!shaka.util.Error} detail
* An object which contains details on the error. The error's
* <code>category</code> and <code>code</code> properties will identify the
* specific error that occurred. In an uncompiled build, you can also use the
* <code>message</code> and <code>stack</code> properties to debug.
* @extends {shaka.util.FakeEvent}
* @export
*/
shaka.events.ErrorEvent = class extends shaka.util.FakeEvent {
/**
* @param {shaka.util.Error} error
*/
constructor(error) {
/** @type {!shaka.util.FakeEvent.EventName} */
const name = shaka.util.FakeEvent.EventName.Error;

/** @type {Map.<string, Object>} */
const data = new Map().set('detail', error);

super(name, data);
}
};
4 changes: 2 additions & 2 deletions lib/media/preload_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ goog.require('shaka.media.QualityObserver');
goog.require('shaka.util.StreamUtils');
goog.require('shaka.media.StreamingEngine');
goog.require('shaka.media.SegmentPrefetch');
goog.require('shaka.events.ErrorEvent');
goog.require('shaka.util.ConfigUtils');
goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.FakeEventTarget');
Expand Down Expand Up @@ -436,8 +437,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
this.destroy();
}

const eventName = shaka.util.FakeEvent.EventName.Error;
const event = this.makeEvent_(eventName, (new Map()).set('detail', error));
const event = new shaka.events.ErrorEvent(error);
this.dispatchEvent(event);
if (event.defaultPrevented) {
error.handled = true;
Expand Down
18 changes: 2 additions & 16 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ goog.require('shaka.media.StreamingEngine');
goog.require('shaka.media.TimeRangesUtils');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.net.NetworkingUtils');
goog.require('shaka.events.ErrorEvent');
goog.require('shaka.text.SimpleTextDisplayer');
goog.require('shaka.text.StubTextDisplayer');
goog.require('shaka.text.TextEngine');
Expand Down Expand Up @@ -70,19 +71,6 @@ goog.require('shaka.lcevc.Dec');
goog.requireType('shaka.media.PresentationTimeline');


/**
* @event shaka.Player.ErrorEvent
* @description Fired when a playback error occurs.
* @property {string} type
* 'error'
* @property {!shaka.util.Error} detail
* An object which contains details on the error. The error's
* <code>category</code> and <code>code</code> properties will identify the
* specific error that occurred. In an uncompiled build, you can also use the
* <code>message</code> and <code>stack</code> properties to debug.
* @exportDoc
*/

/**
* @event shaka.Player.StateChangeEvent
* @description Fired when the player changes load states.
Expand Down Expand Up @@ -7766,9 +7754,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.restoreDisabledVariants_(/* updateAbrManager= */ false);
}

const eventName = shaka.util.FakeEvent.EventName.Error;
const event = shaka.Player.makeEvent_(
eventName, (new Map()).set('detail', error));
const event = new shaka.events.ErrorEvent(error);
this.dispatchEvent(event);
if (event.defaultPrevented) {
error.handled = true;
Expand Down
2 changes: 1 addition & 1 deletion test/test/util/ui_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ shaka.test.UiUtils = class {
config = config || {};
const ui = new shaka.ui.Overlay(player, videoContainer, video, canvas);
// TODO: generate externs automatically from @event types
// This event should be a shaka.Player.ErrorEvent
// This event should be a shaka.events.ErrorEvent
ui.getControls().addEventListener('error', (e) => fail(e['detail']));
ui.configure(config);
return ui;
Expand Down
Loading