@@ -143,14 +143,10 @@ function sendAction(action: Action): void {
143143}
144144
145145async function refreshState ( ) : Promise < void > {
146- try {
147- const [ agents , rooms ] = await Promise . all ( [ fetchAgents ( ) , fetchRooms ( ) ] ) ;
148- state . setAgents ( agents ) ;
149- state . setRooms ( rooms ) ;
150- } catch {
151- // REST API unavailable (standalone PWA) — MeshClient provides state
152- return ;
153- }
146+ if ( ! isLocalServer ) return ;
147+ const [ agents , rooms ] = await Promise . all ( [ fetchAgents ( ) , fetchRooms ( ) ] ) ;
148+ state . setAgents ( agents ) ;
149+ state . setRooms ( rooms ) ;
154150}
155151
156152async function onJoinRoom ( roomId : string ) : Promise < void > {
@@ -160,9 +156,11 @@ async function onJoinRoom(roomId: string): Promise<void> {
160156
161157 sendAction ( { action : "join_room" , room : roomId } ) ;
162158
163- // Load history
164- const messages = await fetchRoomMessages ( roomId ) ;
165- state . setMessages ( messages . map ( roomMessageToDisplay ) ) ;
159+ // Load history (skip REST fetch on standalone PWA — no server)
160+ if ( isLocalServer ) {
161+ const messages = await fetchRoomMessages ( roomId ) ;
162+ state . setMessages ( messages . map ( roomMessageToDisplay ) ) ;
163+ }
166164 addMessage ( { type : "system" , text : `Joined ${ roomId } ` } ) ;
167165}
168166
@@ -282,8 +280,11 @@ const deepLink = parseDeepLink(location.search);
282280
283281// Only connect the direct server WebSocket when served from localhost.
284282// On GitHub Pages / standalone deployments, only MeshClient is used.
285- const localPattern = / ^ ( l o c a l h o s t | 1 2 7 \. \d + \. \d + \. \d + ) ( : \d + ) ? $ / ;
286- if ( localPattern . test ( location . host ) ) {
283+ /** Whether the page is served from a local mesh server (vs standalone PWA). */
284+ const isLocalServer = / ^ ( l o c a l h o s t | 1 2 7 \. \d + \. \d + \. \d + ) ( : \d + ) ? $ / . test (
285+ location . host ,
286+ ) ;
287+ if ( isLocalServer ) {
287288 ws . connect ( ) ;
288289}
289290
0 commit comments