-
Notifications
You must be signed in to change notification settings - Fork 27
fix: implement real-time network IP auto-update via server polling #58
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
base: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (6)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds dynamic local IP polling and broadcasting on the server, updates client SettingsPage to maintain an open WebSocket for live IP updates, and fixes a switch-case fall-through in the input message handler. Changes
Sequence Diagram(s)sequenceDiagram
participant Net as Network Interface
participant Server as App Server (poller)
participant WSS as WebSocket Server
participant Client as Browser SettingsPage
Server->>Net: call getLocalIp() every 5s
Net-->>Server: return current IP
alt IP changed
Server->>WSS: broadcast {type: "server-ip", serverIp}
WSS->>Client: send server-ip message
Client->>Client: update displayed IP / QR
else IP unchanged
Server->>Server: continue polling
end
Note over Client,WSS: On new client connection
Client->>WSS: open WebSocket
WSS->>Client: send {type: "connected", ip: currentIp}
Client->>Client: initialize displayed IP
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@src/routes/settings.tsx`:
- Around line 73-76: The cleanup currently only closes the socket when
socket.readyState === WebSocket.OPEN, missing the CONNECTING state; update the
teardown in the component's cleanup (the return callback where `socket` is
referenced) to close the socket whenever it's not already closing/closed — e.g.
check `socket && socket.readyState !== WebSocket.CLOSING && socket.readyState
!== WebSocket.CLOSED` (or explicitly allow OPEN and CONNECTING) before calling
`socket.close()` so connecting sockets are properly torn down.
In `@src/server/websocket.ts`:
- Line 40: The messages use inconsistent IP property names (some send { serverIp
} while others send { ip }); standardize on a single property (use "ip") across
all message payloads: update the construction of updateMsg (currently
JSON.stringify({ type: 'server-ip', ip: currentIp })) is correct, so change the
payload for the "connected" message and any other sends/broadcasts that use
serverIp to use ip instead (look for occurrences of "serverIp" in the
send/broadcast logic and in functions building the "connected" message) so the
client can always read data.ip.
- Around line 33-47: The setInterval polling in websocket.ts is never cleared
causing a resource leak; modify createWsServer (or the scope where currentIp and
wss are created) to store the interval ID (e.g., pollingIntervalId) returned by
setInterval and add cleanup to clearInterval(pollingIntervalId) when the
WebSocket server closes or is recreated: attach a 'close' handler on wss (or
call clearInterval before creating a new server) to call clearInterval, and also
ensure any process shutdown hooks clear it so intervals don't stack if
createWsServer runs multiple times.
🧹 Nitpick comments (2)
src/routes/settings.tsx (2)
44-77: No reconnection logic if the WebSocket drops.If the server restarts or the connection is lost, the client silently stops receiving IP updates. Consider adding an
onerror/onclosehandler with a retry (e.g., exponential backoff or a simplesetTimeoutreconnect) so the live-update feature is resilient.
59-67: Dual-property handling is a workaround for server inconsistency.The
(data.ip || data.serverIp)check on line 64 exists only because the server sends different property names for different message types. Once the server-side naming is unified (as suggested in the other file), simplify this to a single property.
4970310 to
ff4cae8
Compare
Implement Automatic Network IP & QR Code Update
Fixes #51
Description
This PR addresses the issue where the application's displayed IP address and QR code remained stale when the host machine switched networks (e.g., changing WiFi or connecting to a hotspot). Previously, the IP was only fetched on initial load, requiring a manual refresh to update the connection details.
Changes Made
1. Server-side (Backend)
src/server/websocket.tsto implement a network interface polling mechanism.POLLING_INTERVAL(5 seconds) that checks for IP changes usingos.networkInterfaces().2. Frontend (UI)
src/routes/settings.tsxto maintain a persistent WebSocket connection for IP tracking.server-ipupdate messages and updates the local state in real-time.How to Test
npm run dev.http://localhost:3000/settings).Checklist
npm run build).Summary by CodeRabbit
New Features
Bug Fixes