Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Commit

Permalink
Restore backwards compatibility for overriding HlsHandler's selectPla…
Browse files Browse the repository at this point in the history
…ylist (#795)
  • Loading branch information
gesinger authored and imbcmdth committed Jul 25, 2016
1 parent cf2b906 commit f8af9a2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/videojs-contrib-hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ class HlsHandler extends Component {
// `this` in selectPlaylist should be the HlsHandler for backwards
// compatibility with < v2
this.masterPlaylistController_.selectPlaylist =
Hls.STANDARD_PLAYLIST_SELECTOR.bind(this);
this.selectPlaylist ?
this.selectPlaylist.bind(this) : Hls.STANDARD_PLAYLIST_SELECTOR.bind(this);

// re-expose some internal objects for backwards compatibility with < v2
this.playlists = this.masterPlaylistController_.masterPlaylistLoader_;
Expand Down
44 changes: 44 additions & 0 deletions test/videojs-contrib-hls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,50 @@ QUnit.test('live playlist starts three target durations before live', function()

});

QUnit.test('uses user defined selectPlaylist from HlsHandler if specified', function() {
let origStandardPlaylistSelector = Hls.STANDARD_PLAYLIST_SELECTOR;
let defaultSelectPlaylistCount = 0;

Hls.STANDARD_PLAYLIST_SELECTOR = () => defaultSelectPlaylistCount++;

let hls = HlsSourceHandler('html5').handleSource({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
}, this.tech);

hls.masterPlaylistController_.selectPlaylist();
QUnit.equal(defaultSelectPlaylistCount, 1, 'uses default playlist selector');

defaultSelectPlaylistCount = 0;

let newSelectPlaylistCount = 0;
let newSelectPlaylist = () => newSelectPlaylistCount++;

HlsHandler.prototype.selectPlaylist = newSelectPlaylist;

hls = HlsSourceHandler('html5').handleSource({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
}, this.tech);

hls.masterPlaylistController_.selectPlaylist();
QUnit.equal(defaultSelectPlaylistCount, 0, 'standard playlist selector not run');
QUnit.equal(newSelectPlaylistCount, 1, 'uses overridden playlist selector');

newSelectPlaylistCount = 0;

let setSelectPlaylistCount = 0;

hls.selectPlaylist = () => setSelectPlaylistCount++;

hls.masterPlaylistController_.selectPlaylist();
QUnit.equal(defaultSelectPlaylistCount, 0, 'standard playlist selector not run');
QUnit.equal(newSelectPlaylistCount, 0, 'overridden playlist selector not run');
QUnit.equal(setSelectPlaylistCount, 1, 'uses set playlist selector');

Hls.STANDARD_PLAYLIST_SELECTOR = origStandardPlaylistSelector;
});

QUnit.module('HLS - Encryption', {
beforeEach() {
this.env = useFakeEnvironment();
Expand Down

0 comments on commit f8af9a2

Please sign in to comment.