-
Notifications
You must be signed in to change notification settings - Fork 3
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
fix: clear event binding function references #38
Changes from 1 commit
2adaa99
5b011b6
4f667f4
a0630ca
ff26649
cdebe37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,13 @@ export default class DashAdapter extends BaseMediaSourceAdapter { | |
* @private | ||
*/ | ||
_shaka: any; | ||
/** | ||
* an object containing all the events we bind and unbind to. | ||
* @member {Object} - _adapterEventsBindings | ||
* @type {Object} | ||
* @private | ||
*/ | ||
_adapterEventsBindings: Object = {}; | ||
/** | ||
* The load promise | ||
* @member {Promise<Object>} - _loadPromise | ||
|
@@ -174,6 +181,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { | |
constructor(videoElement: HTMLVideoElement, source: Object, config: Object = {}) { | ||
DashAdapter._logger.debug('Creating adapter. Shaka version: ' + shaka.Player.version); | ||
super(videoElement, source, config); | ||
this._createAdapterFunctionBindings(); | ||
} | ||
|
||
/** | ||
|
@@ -202,19 +210,29 @@ export default class DashAdapter extends BaseMediaSourceAdapter { | |
} | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove redundant lines (!!!) |
||
_createAdapterFunctionBindings(): void{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why empty line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no spoon (empty line). |
||
this._adapterEventsBindings['error'] = this._onError.bind(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use arrow function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, need to clear these bounded methods on destroy or we will have memory leaks possibly |
||
this._adapterEventsBindings['adaption'] = this._onAdaptation.bind(this); | ||
this._adapterEventsBindings['buffering'] = this._onBuffering.bind(this); | ||
this._adapterEventsBindings['waiting'] = this._onWaiting.bind(this); | ||
this._adapterEventsBindings['playing'] = this._onPlaying.bind(this); | ||
} | ||
|
||
/** | ||
* Add the required bindings to shaka. | ||
* @function _addBindings | ||
* @private | ||
* @returns {void} | ||
*/ | ||
_addBindings(): void { | ||
this._shaka.addEventListener('adaptation', this._onAdaptation.bind(this)); | ||
this._shaka.addEventListener('error', this._onError.bind(this)); | ||
this._shaka.addEventListener('buffering', this._onBuffering.bind(this)); | ||
this._shaka.addEventListener('adaptation', this._adapterEventsBindings.adaption); | ||
this._shaka.addEventListener('error', this._adapterEventsBindings.error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create local ENUM for Shaka event names |
||
this._shaka.addEventListener('buffering', this._adapterEventsBindings.buffering); | ||
//TODO use events enum when available | ||
this._videoElement.addEventListener('waiting', this._onWaiting.bind(this)); | ||
this._videoElement.addEventListener('playing', this._onPlaying.bind(this)); | ||
this._videoElement.addEventListener('waiting', this._adapterEventsBindings.waiting); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use ENUM for HTML5 events |
||
this._videoElement.addEventListener('playing', this._adapterEventsBindings.playing); | ||
} | ||
|
||
/** | ||
|
@@ -224,12 +242,12 @@ export default class DashAdapter extends BaseMediaSourceAdapter { | |
* @returns {void} | ||
*/ | ||
_removeBindings(): void { | ||
this._shaka.removeEventListener('adaptation', this._onAdaptation); | ||
this._shaka.removeEventListener('error', this._onError.bind(this)); | ||
this._shaka.removeEventListener('buffering', this._onBuffering.bind(this)); | ||
this._shaka.removeEventListener('adaptation', this._adapterEventsBindings.adaption); | ||
this._shaka.removeEventListener('error', this._adapterEventsBindings.error); | ||
this._shaka.removeEventListener('buffering', this._adapterEventsBindings.buffering); | ||
//TODO use events enum when available | ||
this._videoElement.removeEventListener('waiting', this._onWaiting.bind(this)); | ||
this._videoElement.removeEventListener('playing', this._onPlaying.bind(this)); | ||
this._videoElement.removeEventListener('waiting', this._adapterEventsBindings.waiting); | ||
this._videoElement.removeEventListener('playing', this._adapterEventsBindings.playing); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flow type
{[name: string]: function}