@@ -19,11 +19,14 @@ const testStreams = require('../tests/test-streams');
1919const defaultTestStreamUrl = testStreams [ Object . keys ( testStreams ) [ 0 ] ] . url ;
2020const sourceURL = decodeURIComponent ( getURLParam ( 'src' , defaultTestStreamUrl ) ) ;
2121
22- let demoConfig = getURLParam ( 'demoConfig' , null ) ;
23- if ( demoConfig ) {
24- demoConfig = JSON . parse ( atob ( demoConfig ) ) ;
25- } else {
26- demoConfig = { } ;
22+ let demoConfig = { } ;
23+ const demoConfigParam = getURLParam ( 'demoConfig' , null ) ;
24+ if ( demoConfigParam ) {
25+ try {
26+ demoConfig = JSON . parse ( atob ( demoConfigParam ) ) ;
27+ } catch ( error ) {
28+ console . warn ( 'Failed to parse demoConfig:' , error ) ;
29+ }
2730}
2831
2932const hlsjsDefaults = {
@@ -33,6 +36,18 @@ const hlsjsDefaults = {
3336 backBufferLength : 60 * 1.5 ,
3437} ;
3538
39+ const hlsjsConfigParam = getURLParam ( 'hlsjsConfig' , null ) ;
40+ let hlsjsConfig = hlsjsDefaults ;
41+ let hlsjsConfigLoadedFromUrl = false ;
42+ if ( hlsjsConfigParam ) {
43+ try {
44+ hlsjsConfig = JSON . parse ( atob ( hlsjsConfigParam ) ) ;
45+ hlsjsConfigLoadedFromUrl = true ;
46+ } catch ( error ) {
47+ console . warn ( 'Failed to parse hlsjsConfig:' , error ) ;
48+ }
49+ }
50+
3651let enableStreaming = getDemoConfigPropOrDefault ( 'enableStreaming' , true ) ;
3752let autoRecoverError = getDemoConfigPropOrDefault ( 'autoRecoverError' , true ) ;
3853let levelCapping = getDemoConfigPropOrDefault ( 'levelCapping' , - 1 ) ;
@@ -1473,12 +1488,17 @@ function onDemoConfigChanged(firstLoad) {
14731488 persistEditorValue ( ) ;
14741489 }
14751490
1491+ updatePermalink ( firstLoad ) ;
1492+ }
1493+
1494+ function updatePermalink ( firstLoad ) {
14761495 const serializedDemoConfig = btoa ( JSON . stringify ( demoConfig ) ) ;
1496+ const serializedHlsjsConfig = btoa ( JSON . stringify ( hlsjsConfig ) ) ;
14771497 const baseURL = document . URL . split ( '?' ) [ 0 ] ;
14781498 const streamURL = $ ( '#streamURL' ) . val ( ) ;
14791499 const permalinkURL = `${ baseURL } ?src=${ encodeURIComponent (
14801500 streamURL
1481- ) } &demoConfig=${ serializedDemoConfig } `;
1501+ ) } &demoConfig=${ serializedDemoConfig } &hlsjsConfig= ${ serializedHlsjsConfig } `;
14821502
14831503 $ ( '#StreamPermalink' ) . html ( `<a href="${ permalinkURL } ">${ permalinkURL } </a>` ) ;
14841504 if ( ! firstLoad && self . location . href !== permalinkURL ) {
@@ -1541,8 +1561,9 @@ function setupConfigEditor() {
15411561 configEditor . setTheme ( 'ace/theme/github' ) ;
15421562 configEditor . session . setMode ( 'ace/mode/json' ) ;
15431563
1544- const contents = hlsjsDefaults ;
1564+ const contents = hlsjsConfig ;
15451565 const shouldRestorePersisted =
1566+ ! hlsjsConfigLoadedFromUrl &&
15461567 JSON . parse ( localStorage . getItem ( STORAGE_KEYS . Editor_Persistence ) ) === true ;
15471568
15481569 if ( shouldRestorePersisted ) {
@@ -1713,6 +1734,8 @@ function updateConfigEditorValue(obj) {
17131734
17141735function applyConfigEditorValue ( ) {
17151736 onDemoConfigChanged ( ) ;
1737+ hlsjsConfig = getEditorValue ( { parse : true } ) ;
1738+ updatePermalink ( false ) ;
17161739 loadSelectedStream ( ) ;
17171740}
17181741
0 commit comments