f8af9a26 by Garrett Committed by Jon-Carlos Rivera

Restore backwards compatibility for overriding HlsHandler's selectPlaylist (#795)

1 parent cf2b9066
...@@ -381,7 +381,8 @@ class HlsHandler extends Component { ...@@ -381,7 +381,8 @@ class HlsHandler extends Component {
381 // `this` in selectPlaylist should be the HlsHandler for backwards 381 // `this` in selectPlaylist should be the HlsHandler for backwards
382 // compatibility with < v2 382 // compatibility with < v2
383 this.masterPlaylistController_.selectPlaylist = 383 this.masterPlaylistController_.selectPlaylist =
384 Hls.STANDARD_PLAYLIST_SELECTOR.bind(this); 384 this.selectPlaylist ?
385 this.selectPlaylist.bind(this) : Hls.STANDARD_PLAYLIST_SELECTOR.bind(this);
385 386
386 // re-expose some internal objects for backwards compatibility with < v2 387 // re-expose some internal objects for backwards compatibility with < v2
387 this.playlists = this.masterPlaylistController_.masterPlaylistLoader_; 388 this.playlists = this.masterPlaylistController_.masterPlaylistLoader_;
......
...@@ -2478,6 +2478,50 @@ QUnit.test('live playlist starts three target durations before live', function() ...@@ -2478,6 +2478,50 @@ QUnit.test('live playlist starts three target durations before live', function()
2478 2478
2479 }); 2479 });
2480 2480
2481 QUnit.test('uses user defined selectPlaylist from HlsHandler if specified', function() {
2482 let origStandardPlaylistSelector = Hls.STANDARD_PLAYLIST_SELECTOR;
2483 let defaultSelectPlaylistCount = 0;
2484
2485 Hls.STANDARD_PLAYLIST_SELECTOR = () => defaultSelectPlaylistCount++;
2486
2487 let hls = HlsSourceHandler('html5').handleSource({
2488 src: 'manifest/master.m3u8',
2489 type: 'application/vnd.apple.mpegurl'
2490 }, this.tech);
2491
2492 hls.masterPlaylistController_.selectPlaylist();
2493 QUnit.equal(defaultSelectPlaylistCount, 1, 'uses default playlist selector');
2494
2495 defaultSelectPlaylistCount = 0;
2496
2497 let newSelectPlaylistCount = 0;
2498 let newSelectPlaylist = () => newSelectPlaylistCount++;
2499
2500 HlsHandler.prototype.selectPlaylist = newSelectPlaylist;
2501
2502 hls = HlsSourceHandler('html5').handleSource({
2503 src: 'manifest/master.m3u8',
2504 type: 'application/vnd.apple.mpegurl'
2505 }, this.tech);
2506
2507 hls.masterPlaylistController_.selectPlaylist();
2508 QUnit.equal(defaultSelectPlaylistCount, 0, 'standard playlist selector not run');
2509 QUnit.equal(newSelectPlaylistCount, 1, 'uses overridden playlist selector');
2510
2511 newSelectPlaylistCount = 0;
2512
2513 let setSelectPlaylistCount = 0;
2514
2515 hls.selectPlaylist = () => setSelectPlaylistCount++;
2516
2517 hls.masterPlaylistController_.selectPlaylist();
2518 QUnit.equal(defaultSelectPlaylistCount, 0, 'standard playlist selector not run');
2519 QUnit.equal(newSelectPlaylistCount, 0, 'overridden playlist selector not run');
2520 QUnit.equal(setSelectPlaylistCount, 1, 'uses set playlist selector');
2521
2522 Hls.STANDARD_PLAYLIST_SELECTOR = origStandardPlaylistSelector;
2523 });
2524
2481 QUnit.module('HLS - Encryption', { 2525 QUnit.module('HLS - Encryption', {
2482 beforeEach() { 2526 beforeEach() {
2483 this.env = useFakeEnvironment(); 2527 this.env = useFakeEnvironment();
......