Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: race condition preventing qualityLevels from being populating #707

Merged
merged 6 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<li><a href="test/">Run unit tests in browser.</a></li>
<li><a href="docs/api/">Read generated docs.</a></li>
<li><a href="examples">Browse Examples</a></li>
<li><a href="utils/stats/">Stats</a></li>
</ul>

<script src="node_modules/video.js/dist/alt/video.core.js"></script>
Expand Down
18 changes: 10 additions & 8 deletions scripts/netlify.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const path = require('path');
const sh = require('shelljs');
const fs = require('fs');

const vjs = 'node_modules/video.js/dist/alt/video.core.js';
const vjsCss = 'node_modules/video.js/dist/video-js.css';
const eme = 'node_modules/videojs-contrib-eme/dist/videojs-contrib-eme.js';
const deployDir = 'deploy';
const files = [vjs, vjsCss, eme];

const files = [
'node_modules/video.js/dist/video-js.css',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming files what getting a bit absurd in here

'node_modules/video.js/dist/alt/video.core.js',
'node_modules/videojs-contrib-eme/dist/videojs-contrib-eme.js',
'node_modules/videojs-contrib-quality-levels/dist/videojs-contrib-quality-levels.js',
'node_modules/d3/d3.min.js'
];

// cleanup previous deploy
sh.rm('-rf', deployDir);
Expand All @@ -18,7 +20,7 @@ files
.map((file) => path.dirname(file))
.forEach((dir) => sh.mkdir('-p', path.join(deployDir, dir)));

// copy over files, dist, and html files
// copy files/folders to deploy dir
files
.concat('dist', 'index.html', 'index.min.html')
.concat('dist', 'index.html', 'index.min.html', 'utils')
.forEach((file) => sh.cp('-r', file, path.join(deployDir, file)));
3 changes: 3 additions & 0 deletions src/rendition-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ let renditionSelectionMixin = function(hlsHandler) {

// Add a single API-specific function to the HlsHandler instance
hlsHandler.representations = () => {
if (!playlists || !playlists.master || !playlists.master.playlists) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably return an empty array if we don't have playlists yet, Right now we will just throw an error and some of the tests where failing due to this.

return [];
}
return playlists
.master
.playlists
Expand Down
24 changes: 14 additions & 10 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ class HlsHandler extends Component {
this.tech_.trigger('progress');
});

this.tech_.ready(() => this.setupQualityLevels_());
this.setupQualityLevels_();

// do nothing if the tech has been disposed already
// this can occur if someone sets the src in player.ready(), for instance
Expand All @@ -737,17 +737,21 @@ class HlsHandler extends Component {
setupQualityLevels_() {
let player = videojs.players[this.tech_.options_.playerId];

if (player && player.qualityLevels) {
this.qualityLevels_ = player.qualityLevels();
// if there isn't a player or there isn't a qualityLevels plugin
// or qualityLevels_ listeners have already been setup, do nothing.
if (!player || !player.qualityLevels || this.qualityLevels_) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only setup quality levels listeners once, the rest of the code is the same except we return early instead of adding the logic in an if scope.

return;
}

this.masterPlaylistController_.on('selectedinitialmedia', () => {
handleHlsLoadedMetadata(this.qualityLevels_, this);
});
this.qualityLevels_ = player.qualityLevels();

this.playlists.on('mediachange', () => {
handleHlsMediaChange(this.qualityLevels_, this.playlists);
});
}
this.masterPlaylistController_.on('selectedinitialmedia', () => {
handleHlsLoadedMetadata(this.qualityLevels_, this);
});

this.playlists.on('mediachange', () => {
handleHlsMediaChange(this.qualityLevels_, this.playlists);
});
}

/**
Expand Down
3 changes: 1 addition & 2 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3094,8 +3094,7 @@ QUnit.test('passes useCueTags hls option to master playlist controller', functio
videojs.options.hls = origHlsOptions;
});

// TODO: This test fails intermittently. Turn on when fixed to always pass.
QUnit.skip('populates quality levels list when available', function(assert) {
QUnit.test('populates quality levels list when available', function(assert) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was previously skipped because of intermittent failures. I think fixing this bug fixes the test.

this.player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
Expand Down
30 changes: 14 additions & 16 deletions utils/stats/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<!-- player stats visualization -->
<link href="stats.css" rel="stylesheet">
<script src="/node_modules/d3/d3.min.js"></script>
<script src="../../node_modules/d3/d3.min.js"></script>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have to use local paths to get it to work on netlify.


<style>
body {
Expand Down Expand Up @@ -345,25 +345,23 @@ <h3>Timed Metadata</h3>
videojs.Hls.displayStats(document.querySelector('.switching-stats'), player);
videojs.Hls.displayCues(document.querySelector('.segment-timeline'), player);

player.ready(function() {
var qualityLevels = player.qualityLevels();
var qualityLevels = player.qualityLevels();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quality levels can exist before tech/player ready


qualityLevels.on('addqualitylevel', function(event) {
createQualityButton(event.qualityLevel, qualityButtons);
});
qualityLevels.on('addqualitylevel', function(event) {
createQualityButton(event.qualityLevel, qualityButtons);
});

qualityLevels.on('change', function(event) {
for (var i = 0; i < qualityLevels.length; i++) {
var level = qualityLevels[i];
var button = document.getElementById('quality-level-' + level.id);
qualityLevels.on('change', function(event) {
for (var i = 0; i < qualityLevels.length; i++) {
var level = qualityLevels[i];
var button = document.getElementById('quality-level-' + level.id);

button.classList.remove('selected');
}
button.classList.remove('selected');
}

var selected = qualityLevels[event.selectedIndex];
var button = document.getElementById('quality-level-' + selected.id);
button.classList.add('selected');
});
var selected = qualityLevels[event.selectedIndex];
var button = document.getElementById('quality-level-' + selected.id);
button.classList.add('selected');
});
});
}
Expand Down