Skip to content

Commit

Permalink
Update demo URL with pushState() (video-dev#4327)
Browse files Browse the repository at this point in the history
* Update demo URL with pushState()

That way people won't have to remember to copy the permalink.

* Apply suggestions from code review

Co-authored-by: Tom Jenkinson <[email protected]>

* Add simple first load protection

We can't just check if we're on baseURL, because then it'd never activate.

I don't immediately see a better method, give or take perhaps where you set the variables.

* Change firstLoad as per review

* Fix comparison (window.location is a Location object)

* use location.href

Co-authored-by: Tom Jenkinson <[email protected]>
  • Loading branch information
Frenzie and tjenkinson authored Sep 22, 2021
1 parent c5d48d4 commit 8c41dff
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ $(document).ready(function () {
toggleTab($('.demo-tab-btn')[parseInt(indexString) || 0], true);
});
}
$(window).on('popstate', function () {
window.location.reload();
});
});

function setupGlobals() {
Expand Down Expand Up @@ -334,7 +337,7 @@ function loadSelectedStream() {
updateConfigEditorValue(hlsConfig);
}

onDemoConfigChanged();
onDemoConfigChanged(true);
console.log('Using Hls.js config:', hlsConfig);

self.hls = hls = new Hls(hlsConfig);
Expand Down Expand Up @@ -1459,7 +1462,7 @@ function getURLParam(sParam, defaultValue) {
return defaultValue;
}

function onDemoConfigChanged() {
function onDemoConfigChanged(firstLoad) {
demoConfig = {
enableStreaming,
autoRecoverError,
Expand All @@ -1481,6 +1484,9 @@ function onDemoConfigChanged() {
)}&demoConfig=${serializedDemoConfig}`;

$('#StreamPermalink').html(`<a href="${permalinkURL}">${permalinkURL}</a>`);
if (!firstLoad && window.location.href !== permalinkURL) {
window.history.pushState(null, null, permalinkURL);
}
}

function onConfigPersistenceChanged(event) {
Expand Down

0 comments on commit 8c41dff

Please sign in to comment.