Skip to content

feat(cameras): Pick the next free port when adding a stream endpoint - #566

Merged
brandonhs merged 1 commit into
mainfrom
feat/auto-increment-endpoint-port
Oct 20, 2026
Merged

brandonhs merged 1 commit into
mainfrom
feat/auto-increment-endpoint-port

Conversation

@Tekunalogy

@Tekunalogy Tekunalogy commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Closes #565

What

The + button on a camera's endpoint list used to always add the default endpoint from Preferences (usually 192.168.2.1:5600), so every new endpoint collided on the same port. Now it picks the lowest port at or above the default that no endpoint on any camera uses:

  • first endpoint anywhere: 5600 (the Preferences default)
  • next ones: 5601, 5602, ... across all cameras
  • deleting an endpoint frees its port, so the next one added fills the gap
  • editing a port by hand is unchanged

How

  • getNextAvailablePort(devices, startPort) in lib/util/device.ts: collects used ports into a Set and counts up from startPort, O(n) in the number of endpoints.
  • endpoint-list.tsx: on click, re-fetches /api/devices/map first so ports used by streams this tab missed (stale tab, dropped socket event) still count, then adds the endpoint. The button is disabled while that runs, so a double click can't add two endpoints on the same port.

Host is ignored when checking for collisions, to keep the rule simple. Backend is unchanged.

Testing

  • Throwaway script for getNextAvailablePort: empty, gaps, ports across cameras, unordered, duplicates, ports below the default, custom default
  • eslint, tsc -b, npm run build
  • On a device (Pi with two cameras): add endpoints on two cameras → 5600, 5601, 5602; delete the middle one and add again → reuses it

🤖 Generated with Claude Code

New endpoints used to always get the default port from preferences, so
every camera added after the first collided on the receiver. The add
button now uses the lowest port at or above the default that no camera's
endpoints use, refreshing the device list from the backend first so
streams this tab hasn't heard about yet still count.

Closes #565

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Preview build preview-pr-566 deleted.

@Tekunalogy
Tekunalogy marked this pull request as ready for review October 15, 2026 21:23
@brandonhs

Copy link
Copy Markdown
Member

LGTM

@brandonhs
brandonhs merged commit af48b64 into main Oct 20, 2026
5 checks passed
@brandonhs
brandonhs deleted the feat/auto-increment-endpoint-port branch October 20, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

camera endpoint increment

2 participants