-
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
Conversation
src/dash-adapter.js
Outdated
* @type {Object} | ||
* @private | ||
*/ | ||
_adapterEventsBindings: Object = {}; |
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}
src/dash-adapter.js
Outdated
@@ -202,19 +210,29 @@ export default class DashAdapter extends BaseMediaSourceAdapter { | |||
} | |||
} | |||
|
|||
|
|||
_createAdapterFunctionBindings(): void{ | |||
|
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.
why empty line?
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.
there is no spoon (empty line).
src/dash-adapter.js
Outdated
|
||
_createAdapterFunctionBindings(): void{ | ||
|
||
this._adapterEventsBindings['error'] = this._onError.bind(this); |
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.
can we use arrow function?
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.
also, need to clear these bounded methods on destroy or we will have memory leaks possibly
src/dash-adapter.js
Outdated
//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 comment
The reason will be displayed to describe this comment to others. Learn more.
Use ENUM for HTML5 events
src/dash-adapter.js
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Create local ENUM for Shaka event names
src/dash-adapter.js
Outdated
ERROR: 'error' , | ||
ADAPTION: 'adaption', | ||
BUFFERING: 'buffering', | ||
WAITING: 'waiting', |
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.
WAITING and PLAYING are HTML5 events
src/dash-adapter.js
Outdated
@@ -7,6 +7,20 @@ import {Error} from 'playkit-js' | |||
import Widevine from './drm/widevine' | |||
import PlayReady from './drm/playready' | |||
|
|||
|
|||
type ShakaEventsType = { [event: string]: string }; |
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.
change to ShakaEventType
src/dash-adapter.js
Outdated
* @type {Object} | ||
* @const | ||
*/ | ||
const SHAKA_EVENTS: ShakaEventsType = { |
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.
Enums convention are to lead with capitals and refer as singular (i.e. ShakaEvent
)
src/dash-adapter.js
Outdated
@@ -202,19 +224,27 @@ export default class DashAdapter extends BaseMediaSourceAdapter { | |||
} | |||
} | |||
|
|||
|
|||
_createAdapterFunctionBindings(): void { |
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.
We can do this logic statically when we declare the _adapterEventsBindings
variable, no need to create method for it
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.
@dan-ziv what do you mean statically? we want to have the this bindings
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.
_adapterEventsBindings: { [name: string]: Function } = {
[ShakaEvent.ERROR] : (event) => this._onError(event),
...
};
src/dash-adapter.js
Outdated
@@ -202,19 +224,27 @@ export default class DashAdapter extends BaseMediaSourceAdapter { | |||
} | |||
} | |||
|
|||
|
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.
remove redundant lines (!!!)
cleaning code
Description of the Changes
Created an object to hold all the event handlers, so we can unbind it properly.
Today we don't really unbind the handler because it's a new handler and not a reference to the previous one.
CheckLists