Skip to content

Commit

Permalink
fix: remove player props on dispose to stop middleware (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored and forbesjo committed Dec 6, 2018
1 parent a35dd09 commit cd13f9f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/mse/html-media-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ export default class HtmlMediaSource extends videojs.EventTarget {

this.player_ = videojs(video.parentNode);

if (!this.player_) {
return;
}

// hls-reset is fired by videojs.Hls on to the tech after the main SegmentLoader
// resets its state and flushes the buffer
this.player_.tech_.on('hls-reset', this.onHlsReset_);
Expand Down Expand Up @@ -252,6 +256,9 @@ export default class HtmlMediaSource extends videojs.EventTarget {
// event handlers left to unbind anyway
if (this.player_.el_) {
this.player_.off('mediachange', this.onPlayerMediachange_);
}

if (this.player_.tech_ && this.player_.tech_.el_) {
this.player_.tech_.off('hls-reset', this.onHlsReset_);
this.player_.tech_.off('hls-segment-time-mapping', this.onHlsSegmentTimeMapping_);
}
Expand Down
16 changes: 15 additions & 1 deletion src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ class HlsHandler extends Component {
videojs.log.warn('player.hls is deprecated. Use player.tech().hls instead.');
tech.trigger({ type: 'usage', name: 'hls-player-access' });
return this;
}
},
configurable: true
});
}

Expand All @@ -337,6 +338,8 @@ class HlsHandler extends Component {
_player.vhs = this;
// deprecated, for backwards compatibility
_player.dash = this;

this.player_ = _player;
}

this.tech_ = tech;
Expand Down Expand Up @@ -736,6 +739,17 @@ class HlsHandler extends Component {
if (this.qualityLevels_) {
this.qualityLevels_.dispose();
}

if (this.player_) {
delete this.player_.vhs;
delete this.player_.dash;
delete this.player_.hls;
}

if (this.tech_ && this.tech_.hls) {
delete this.tech_.hls;
}

super.dispose();
}

Expand Down
19 changes: 10 additions & 9 deletions test/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,16 @@ export const openMediaSource = function(player, clock) {
// mock the tech *after* it has finished loading so that we don't
// mock a tech that will be unloaded on the next tick
mockTech(player.tech_);
player.tech_.hls.xhr = xhrFactory();

// simulate the sourceopen event
player.tech_.hls.mediaSource.readyState = 'open';
player.tech_.hls.mediaSource.dispatchEvent({
type: 'sourceopen',
swfId: player.tech_.el().id
});
clock.tick(1);
if (player.tech_.hls) {
player.tech_.hls.xhr = xhrFactory();
// simulate the sourceopen event
player.tech_.hls.mediaSource.readyState = 'open';
player.tech_.hls.mediaSource.dispatchEvent({
type: 'sourceopen',
swfId: player.tech_.el() && player.tech_.el().id
});
clock.tick(1);
}
};

export const standardXHRResponse = function(request, data) {
Expand Down
2 changes: 2 additions & 0 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,7 @@ QUnit.test('configures eme if present on selectedinitialmedia', function(assert)
}
};
this.player.tech_.hls.masterPlaylistController_.mediaTypes_ = {
SUBTITLES: {},
AUDIO: {
activePlaylistLoader: {
media: () => {
Expand Down Expand Up @@ -2941,6 +2942,7 @@ QUnit.test('does not set source keySystems if keySystems not provided by source'
}
};
this.player.tech_.hls.masterPlaylistController_.mediaTypes_ = {
SUBTITLES: {},
AUDIO: {
activePlaylistLoader: {
media: () => {
Expand Down

0 comments on commit cd13f9f

Please sign in to comment.