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
Changes from 1 commit
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
48 changes: 31 additions & 17 deletions src/dash-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ 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


/**
* Shaka events enum
* @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)

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

PLAYING: 'playing'
};

/**
* Adapter of shaka lib for dash content
* @classdesc
Expand Down Expand Up @@ -212,11 +228,11 @@ 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 (!!!)

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

this._adapterEventsBindings['error'] = (event) => this._onError(event);
this._adapterEventsBindings['adaption'] = () => this._onAdaptation();
this._adapterEventsBindings['buffering'] = (event) => this._onBuffering(event);
this._adapterEventsBindings['waiting'] = () => this._onWaiting();
this._adapterEventsBindings['playing'] = () => this._onPlaying();
this._adapterEventsBindings[SHAKA_EVENTS.ERROR] = (event) => this._onError(event);
this._adapterEventsBindings[SHAKA_EVENTS.ADAPTION] = () => this._onAdaptation();
this._adapterEventsBindings[SHAKA_EVENTS.BUFFERING] = (event) => this._onBuffering(event);
this._adapterEventsBindings[SHAKA_EVENTS.WAITING] = () => this._onWaiting();
this._adapterEventsBindings[SHAKA_EVENTS.PLAYING] = () => this._onPlaying();
}

/**
Expand All @@ -226,12 +242,11 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
* @returns {void}
*/
_addBindings(): void {
this._shaka.addEventListener('adaptation', this._adapterEventsBindings.adaption);
this._shaka.addEventListener('error', this._adapterEventsBindings.error);
this._shaka.addEventListener('buffering', this._adapterEventsBindings.buffering);
//TODO use events enum when available
this._videoElement.addEventListener('waiting', this._adapterEventsBindings.waiting);
this._videoElement.addEventListener('playing', this._adapterEventsBindings.playing);
this._shaka.addEventListener(SHAKA_EVENTS.ADAPTION, this._adapterEventsBindings.adaption);
this._shaka.addEventListener(SHAKA_EVENTS.ERROR, this._adapterEventsBindings.error);
this._shaka.addEventListener(SHAKA_EVENTS.BUFFERING, this._adapterEventsBindings.buffering);
this._videoElement.addEventListener(SHAKA_EVENTS.WAITING, this._adapterEventsBindings.waiting);
this._videoElement.addEventListener(SHAKA_EVENTS.PLAYING, this._adapterEventsBindings.playing);
}

/**
Expand All @@ -241,12 +256,11 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
* @returns {void}
*/
_removeBindings(): void {
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._adapterEventsBindings.waiting);
this._videoElement.removeEventListener('playing', this._adapterEventsBindings.playing);
this._shaka.removeEventListener(SHAKA_EVENTS.ADAPTION, this._adapterEventsBindings.adaption);
this._shaka.removeEventListener(SHAKA_EVENTS.ERROR, this._adapterEventsBindings.error);
this._shaka.removeEventListener(SHAKA_EVENTS.BUFFERING, this._adapterEventsBindings.buffering);
this._videoElement.removeEventListener(SHAKA_EVENTS.WAITING, this._adapterEventsBindings.waiting);
this._videoElement.removeEventListener(SHAKA_EVENTS.PLAYING, this._adapterEventsBindings.playing);
}

/**
Expand Down