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

fix: clear event binding function references #38

Merged
merged 6 commits into from
Dec 12, 2017
Merged

Conversation

odedhutzler
Copy link
Contributor

@odedhutzler odedhutzler commented Dec 6, 2017

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

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • test are passing in local environment
  • Travis tests are passing (or test results are not worse than on master branch :))
  • Docs have been updated

* @type {Object}
* @private
*/
_adapterEventsBindings: Object = {};
Copy link
Contributor

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}

@@ -202,19 +210,29 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
}
}


_createAdapterFunctionBindings(): void{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why empty line?

Copy link
Contributor Author

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).


_createAdapterFunctionBindings(): void{

this._adapterEventsBindings['error'] = this._onError.bind(this);
Copy link
Contributor

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?

Copy link
Contributor

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

@OrenMe OrenMe changed the title fix: create an object for all the binding functions references. fix: clear event binding functions references Dec 7, 2017
@OrenMe OrenMe changed the title fix: clear event binding functions references fix: clear event binding function references Dec 7, 2017
//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);
Copy link
Contributor

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

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);
Copy link
Contributor

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

ERROR: 'error' ,
ADAPTION: 'adaption',
BUFFERING: 'buffering',
WAITING: 'waiting',
Copy link
Contributor

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

OrenMe
OrenMe previously approved these changes Dec 7, 2017
@@ -7,6 +7,20 @@ import {Error} from 'playkit-js'
import Widevine from './drm/widevine'
import PlayReady from './drm/playready'


type ShakaEventsType = { [event: string]: string };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to ShakaEventType

* @type {Object}
* @const
*/
const SHAKA_EVENTS: ShakaEventsType = {
Copy link
Contributor

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)

@@ -202,19 +224,27 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
}
}


_createAdapterFunctionBindings(): void {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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),
...
};

@@ -202,19 +224,27 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove redundant lines (!!!)

@dan-ziv dan-ziv merged commit 58beee8 into master Dec 12, 2017
@dan-ziv dan-ziv deleted the event_binding_handler branch December 12, 2017 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants