Skip to content

Conversation

@gmegidish
Copy link
Member

@gmegidish gmegidish commented Jan 18, 2026

Summary by CodeRabbit

  • New Features

    • iOS real devices now support AVC video format.
  • Bug Fixes

    • Improved port allocation mechanism with range-based discovery for enhanced device connectivity.
    • Upgraded timeout handling with configurable values for device initialization operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 18, 2026

Walkthrough

Refactored port allocation and forwarding in iOS device handling to use port ranges and constants instead of single ports, replaced fixed sleeps with configurable timeouts, extended AVC format support to iOS real devices while blocking on simulators, and added a port range finder utility function.

Changes

Cohort / File(s) Summary
iOS Device Port & Timeout Configuration
devices/ios.go
Introduced port range constants and device port targets; replaced single-port discovery with range-based finder; refactored port forwarding to two-step HTTP+stream approach; replaced hard-coded sleeps with configurable timeouts.
Server Screen Capture Format Validation
server/server.go
Broadened AVC format support from Android-only to include iOS real devices, while explicitly blocking AVC on iOS simulators.
Port Manager Utilities
utils/port-manager.go
Added FindAvailablePortInRange() function to find available ports within a specified range; improved IsPortAvailable() error logging to reduce noise for "address already in use" scenarios.

Possibly related PRs

  • PR #112: Modifies screen-capture format validation and iOS AVC support logic alongside the server.go changes in this PR.
  • PR #110: Modifies devices/ios.go StartAgent and StartScreenCapture flow signatures, directly related to port allocation changes here.
  • PR #145: Modifies iOS devicekit streaming code in devices/ios.go with port-forwarding and range-based port discovery patterns introduced in this PR.
🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title focuses on reducing logs for port-already-in-use scenarios, but the changeset includes substantial port range management refactoring and AVC format validation changes beyond just logging reduction. Update the title to reflect the primary changes, such as 'refactor: implement port range management and port forwarding logic' or clarify if logging reduction is the main objective.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
utils/port-manager.go (1)

24-31: Consolidate duplicate port-finding logic to reduce maintenance burden.

The codebase has two identical implementations of the same port-finding logic:

  • FindAvailablePortInRange in utils/port-manager.go (used in devices/simulator.go)
  • findAvailablePortInRange in devices/ios.go (used locally 4 times: lines 334, 384, 893, 906)

The devices/ios.go file should use the exported utils.FindAvailablePortInRange function instead of maintaining its own copy to avoid duplication and reduce maintenance overhead.

🧹 Nitpick comments (2)
devices/ios.go (2)

1000-1007: Duplicate of utils.FindAvailablePortInRange.

This local function duplicates the exported FindAvailablePortInRange in utils/port-manager.go. Consider removing this and using utils.FindAvailablePortInRange instead for consistency and to avoid duplication.

♻️ Proposed fix

Remove this function and update callers to use the utils version:

-// findAvailablePortInRange finds an available port in the specified range
-func findAvailablePortInRange(start, end int) (int, error) {
-	for port := start; port <= end; port++ {
-		if utils.IsPortAvailable("localhost", port) {
-			return port, nil
-		}
-	}
-	return 0, fmt.Errorf("no available ports found in range %d-%d", start, end)
-}

Then update all callers (lines 334, 384, 893, 906) from findAvailablePortInRange(...) to utils.FindAvailablePortInRange(...).


383-398: Remove if true block wrapper.

The if true { on line 383 is always true, making it dead conditional logic. This appears to be leftover from debugging or development. The block contents should remain, but the conditional wrapper should be removed.

♻️ Proposed fix
-	// assuming everything went well if we reached this point
-	if true {
-		portMjpeg, err := findAvailablePortInRange(portRangeStart, portRangeEnd)
+	// Set up MJPEG port forwarding
+	portMjpeg, err := findAvailablePortInRange(portRangeStart, portRangeEnd)
...
-	}

@gmegidish
Copy link
Member Author

Closing, too many conflicts

@gmegidish gmegidish closed this Jan 18, 2026
@gmegidish gmegidish deleted the fix-reduce-logs-on-port-in-use branch January 18, 2026 18:28
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.

2 participants