Skip to content

Commit

Permalink
EventHandler: reserve/handler-built-in events "hlsHandlerDestroying" …
Browse files Browse the repository at this point in the history
…and "hlsHandlerDestroyed"
  • Loading branch information
tchakabam committed Dec 11, 2017
1 parent 7ad8819 commit f9ab77f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/controller/audio-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class AudioStreamController extends TaskLoop {
this.videoTrackCC = null;
}

_onDestroying() {
onHandlerDestroying() {
this.stopLoad();
}

_onDestroyed() {
onHandlerDestroyed() {
this.state = State.STOPPED;
}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/level-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class LevelController extends EventHandler {
this.timer = null;
}

_onDestroying() {
onHandlerDestroying() {
this.cleanTimer();
this.manualLevelIndex = -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ class StreamController extends TaskLoop {
this._state = State.STOPPED;
}

_onDestroying() {
onHandlerDestroying() {
this.stopLoad();
}

_onDestroyed() {
onHandlerDestroyed() {
this.state = State.STOPPED;
}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/subtitle-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SubtitleStreamController extends TaskLoop {
this.decrypter = new Decrypter(hls.observer, hls.config);
}

_onDestroyed() {
onHandlerDestroyed() {
this.state = State.STOPPED;
}

Expand Down
18 changes: 12 additions & 6 deletions src/event-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import {logger} from './utils/logger';
import {ErrorTypes, ErrorDetails} from './errors';
import Event from './events';

const FORBIDDEN_EVENT_NAMES = [
'hlsEventGeneric',
'hlsHandlerDestroying',
'hlsHandlerDestroyed'
];

class EventHandler {

constructor(hls, ...events) {
Expand All @@ -20,13 +26,13 @@ class EventHandler {
}

destroy() {
this._onDestroying();
this.onHandlerDestroying();
this.unregisterListeners();
this._onDestroyed();
this.onHandlerDestroyed();
}

_onDestroying() {}
_onDestroyed() {}
onHandlerDestroying() {}
onHandlerDestroyed() {}

isEventHandler() {
return typeof this.handledEvents === 'object' && this.handledEvents.length && typeof this.onEvent === 'function';
Expand All @@ -35,8 +41,8 @@ class EventHandler {
registerListeners() {
if (this.isEventHandler()) {
this.handledEvents.forEach(function(event) {
if (event === 'hlsEventGeneric') {
throw new Error('Forbidden event name: ' + event);
if (FORBIDDEN_EVENT_NAMES.includes(event)) {
throw new Error('Forbidden event-name: ' + event);
}
this.hls.on(event, this.onEvent);
}, this);
Expand Down

0 comments on commit f9ab77f

Please sign in to comment.