Skip to content

Conversation

Neplex
Copy link
Contributor

@Neplex Neplex commented Sep 14, 2025

The web UI failed to connect to the WebSocket server when no port was specified, because the client appended an invalid :0 port. This is fixed by explicitly using the default port when no port is provided: 443 for wss:// and 80 for ws://.

Linked issue: rikulo/socket.io-client-dart#222

To support more complex setups with custom public port, it would require to be able to specify a custom port or even let the user set the public address manually of both panel and websocket

Summary by CodeRabbit

  • Bug Fixes
    • WebSocket connections now always include an explicit port (defaults to 443 for secure, 80 for non-secure) when none is provided, reducing connection ambiguity.
    • Scheme selection for sockets is now more consistent between secure and non-secure modes, improving connectivity reliability across environments.

Copy link
Contributor

coderabbitai bot commented Sep 14, 2025

Walkthrough

SocketNotifier.init now always builds a WebSocket URL with an explicit port and scheme. It derives the scheme from the secure flag, chooses default ports (443/80) when port is null or 0, and appends the token query if present. No other logic or public APIs changed.

Changes

Cohort / File(s) Summary
WebSocket URL construction
app/lib/models/communicator.dart
Refactored URL building in SocketNotifier.init: derive scheme (wss/ws), compute socketPort with defaults (443/80) when port is null or 0, always include explicit :port in the URL, and preserve optional ?token= query. No other functional changes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant App
    participant SocketNotifier
    participant WS as WebSocket Server

    App->>SocketNotifier: init(secure, hostname, port, token)
    rect rgba(200,230,255,0.25)
    note right of SocketNotifier: Build URL with explicit scheme and port
    SocketNotifier->>SocketNotifier: scheme = secure ? "wss" : "ws"
    SocketNotifier->>SocketNotifier: socketPort = (port == null || port == 0) ? (secure ? 443 : 80) : port
    SocketNotifier->>SocketNotifier: url = scheme + "://" + hostname + ":" + socketPort + [ "?token=..." ]
    end
    SocketNotifier->>WS: Connect(url)
    WS-->>SocketNotifier: Upgrade/Establish
    SocketNotifier-->>App: Ready / connected
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitched my whiskers, ports aligned,
From ws to wss, the scheme refined.
Eighty or four-four-three, set true—
A tidy URL, hop-hop, woo!
With tokens tucked, I bound the thread,
And leapt into the socket’s web. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Force default WebSocket port to prevent :0 errors" accurately and concisely summarizes the primary change—defaulting the WebSocket port to 443/80 to avoid invalid ":0" ports—and matches the PR description and code diff, making it clear and specific for reviewers.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5bc0501 and 5b798a7.

📒 Files selected for processing (1)
  • app/lib/models/communicator.dart (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/lib/models/communicator.dart

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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
Contributor

@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: 1

Caution

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

⚠️ Outside diff range comments (1)
app/lib/models/communicator.dart (1)

120-121: Do not log the auth token; redact it.

Token in debug logs is a credential leak.

-    debugPrint("Initializing socket to $url");
+    final logUri =
+        token == null ? uri : uri.replace(queryParameters: {'token': 'REDACTED'});
+    debugPrint("Initializing socket to $logUri");
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e075d02 and 9fee65f.

📒 Files selected for processing (1)
  • app/lib/models/communicator.dart (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/**/*.dart

📄 CodeRabbit inference engine (app/AGENTS.md)

app/**/*.dart: Use standard Dart formatting via flutter format for all Dart source files
Keep Dart files under 300 lines where possible

Files:

  • app/lib/models/communicator.dart
🔇 Additional comments (1)
app/lib/models/communicator.dart (1)

115-119: Confirm hostname semantics (no scheme/port/path).

Found call at app/lib/pages/connect_page.dart:44–46 (ref.read(socketProvider.notifier).init(hostname, port)) — verify that hostname is a bare host (no "http(s)://", no ":port", no path). If callers can pass "host:port" or a full URL, either sanitize/normalize the input at the call sites or update communicator.init to parse/construct the URI (use Uri.parse/Uri(scheme:..., host:..., port:...) or explicitly strip scheme/port/path) to avoid producing invalid URLs.

@gabber235 gabber235 merged commit 939b9b0 into gabber235:develop Sep 20, 2025
2 checks passed
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