@@ -77,20 +77,26 @@ export function WebRTCView() {
7777 // State for go2rtc availability (to show MSE View button)
7878 const [ go2rtcAvailable , setGo2rtcAvailable ] = useState ( false ) ;
7979
80- // Initialize cols/rows from URL params, localStorage, or legacy layout key.
80+ // Initialize cols/rows from URL params, shared localStorage key, or legacy per-view keys.
81+ // All live views (WebRTC / HLS / MSE) share 'lightnvr-live-cols' / 'lightnvr-live-rows'
82+ // so a layout change on one page carries over to the others.
8183 // autoGrid stays true when no preference exists — streams-load effect will
8284 // auto-size the grid to fit the available camera count.
8385 const [ autoGrid , setAutoGrid ] = useState ( ( ) => {
8486 const p = new URLSearchParams ( window . location . search ) ;
85- return p . get ( 'cols' ) === null && localStorage . getItem ( 'lightnvr-webrtc-cols' ) === null
87+ return p . get ( 'cols' ) === null
88+ && localStorage . getItem ( 'lightnvr-live-cols' ) === null
89+ && localStorage . getItem ( 'lightnvr-webrtc-cols' ) === null
8690 && localStorage . getItem ( 'lightnvr-webrtc-layout' ) === null ;
8791 } ) ;
8892 const [ cols , setCols ] = useState ( ( ) => {
8993 const urlParams = new URLSearchParams ( window . location . search ) ;
9094 const cp = urlParams . get ( 'cols' ) ;
9195 if ( cp ) return Math . max ( 1 , Math . min ( 9 , parseInt ( cp , 10 ) || 2 ) ) ;
92- const stored = localStorage . getItem ( 'lightnvr-webrtc-cols' ) ;
93- if ( stored ) return Math . max ( 1 , Math . min ( 9 , parseInt ( stored , 10 ) || 2 ) ) ;
96+ const shared = localStorage . getItem ( 'lightnvr-live-cols' ) ;
97+ if ( shared ) return Math . max ( 1 , Math . min ( 9 , parseInt ( shared , 10 ) || 2 ) ) ;
98+ const legacy = localStorage . getItem ( 'lightnvr-webrtc-cols' ) ;
99+ if ( legacy ) return Math . max ( 1 , Math . min ( 9 , parseInt ( legacy , 10 ) || 2 ) ) ;
94100 const oldLayout = localStorage . getItem ( 'lightnvr-webrtc-layout' ) ;
95101 if ( oldLayout ) return legacyLayoutToColsRowsWebRTC ( oldLayout ) [ 0 ] ;
96102 return 2 ; // placeholder until autoGrid resolves
@@ -99,8 +105,10 @@ export function WebRTCView() {
99105 const urlParams = new URLSearchParams ( window . location . search ) ;
100106 const rp = urlParams . get ( 'rows' ) ;
101107 if ( rp ) return Math . max ( 1 , Math . min ( 9 , parseInt ( rp , 10 ) || 2 ) ) ;
102- const stored = localStorage . getItem ( 'lightnvr-webrtc-rows' ) ;
103- if ( stored ) return Math . max ( 1 , Math . min ( 9 , parseInt ( stored , 10 ) || 2 ) ) ;
108+ const shared = localStorage . getItem ( 'lightnvr-live-rows' ) ;
109+ if ( shared ) return Math . max ( 1 , Math . min ( 9 , parseInt ( shared , 10 ) || 2 ) ) ;
110+ const legacy = localStorage . getItem ( 'lightnvr-webrtc-rows' ) ;
111+ if ( legacy ) return Math . max ( 1 , Math . min ( 9 , parseInt ( legacy , 10 ) || 2 ) ) ;
104112 const oldLayout = localStorage . getItem ( 'lightnvr-webrtc-layout' ) ;
105113 if ( oldLayout ) return legacyLayoutToColsRowsWebRTC ( oldLayout ) [ 1 ] ;
106114 return 2 ; // placeholder until autoGrid resolves
@@ -262,8 +270,11 @@ export function WebRTCView() {
262270 // Persist to storage
263271 if ( currentPage > 0 ) sessionStorage . setItem ( 'webrtc_current_page' , ( currentPage + 1 ) . toString ( ) ) ;
264272 else sessionStorage . removeItem ( 'webrtc_current_page' ) ;
265- localStorage . setItem ( 'lightnvr-webrtc-cols' , String ( cols ) ) ;
266- localStorage . setItem ( 'lightnvr-webrtc-rows' , String ( rows ) ) ;
273+ localStorage . setItem ( 'lightnvr-live-cols' , String ( cols ) ) ;
274+ localStorage . setItem ( 'lightnvr-live-rows' , String ( rows ) ) ;
275+ // Clean up old per-view keys so reads don't fall back to stale values
276+ localStorage . removeItem ( 'lightnvr-webrtc-cols' ) ;
277+ localStorage . removeItem ( 'lightnvr-webrtc-rows' ) ;
267278 localStorage . removeItem ( 'lightnvr-webrtc-layout' ) ;
268279 if ( isSingleStream && selectedStream ) sessionStorage . setItem ( 'webrtc_selected_stream' , selectedStream ) ;
269280 else sessionStorage . removeItem ( 'webrtc_selected_stream' ) ;
0 commit comments