Skip to content

Commit

Permalink
fix: remove both vttjs listeners to prevent leaking one of them (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored and gkatsev committed May 9, 2019
1 parent ad6f292 commit 1db1e72
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/vtt-segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,25 @@ export default class VTTSegmentLoader extends SegmentLoader {
this.subtitlesTrack_ &&
this.subtitlesTrack_.tech_) {

const loadHandler = () => {
this.handleSegment_();
};

this.state = 'WAITING_ON_VTTJS';
this.subtitlesTrack_.tech_.one('vttjsloaded', loadHandler);
this.subtitlesTrack_.tech_.one('vttjserror', () => {
let loadHandler;
const errorHandler = () => {
this.subtitlesTrack_.tech_.off('vttjsloaded', loadHandler);
this.error({
message: 'Error loading vtt.js'
});
this.state = 'READY';
this.pause();
this.trigger('error');
});
};

loadHandler = () => {
this.subtitlesTrack_.tech_.off('vttjserror', errorHandler);
this.handleSegment_();
};

this.state = 'WAITING_ON_VTTJS';
this.subtitlesTrack_.tech_.one('vttjsloaded', loadHandler);
this.subtitlesTrack_.tech_.one('vttjserror', errorHandler);

return;
}
Expand Down

0 comments on commit 1db1e72

Please sign in to comment.