Skip to content

Commit 71650f8

Browse files
committed
Revert to explicit port 443 to fix port :0 issue
1 parent fa26a1c commit 71650f8

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

lib/services/music_assistant_api.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,25 @@ class MusicAssistantAPI {
101101
_logger.log('Attempting ${useSecure ? "secure (WSS)" : "unsecure (WS)"} connection');
102102
_logger.log('Final WebSocket URL: $wsUrl');
103103

104-
// For Cloudflare and reverse proxies, don't include explicit port 443 for WSS
105-
// Build the connection URL appropriately
104+
// WebSocket.connect() parses URL strings and sets port to 0 if not explicit
105+
// We MUST include explicit port to avoid port :0 bug
106106
String connectionUrl;
107107
if (_cachedCustomPort != null) {
108108
// Custom port - include it explicitly
109109
connectionUrl = '${uri.scheme}://${uri.host}:$_cachedCustomPort/ws';
110110
_logger.log('Using custom port in URL: $connectionUrl');
111-
} else if (uri.hasPort && uri.port != 0 && !(useSecure && uri.port == 443)) {
112-
// Explicit non-default port in URL - include it (but not 443 for WSS)
111+
} else if (uri.hasPort && uri.port != 0) {
112+
// Explicit port in URL - include it
113113
connectionUrl = '${uri.scheme}://${uri.host}:${uri.port}/ws';
114114
_logger.log('Using explicit port in URL: $connectionUrl');
115115
} else if (!useSecure) {
116116
// Unsecure connection - use port 8095
117117
connectionUrl = '${uri.scheme}://${uri.host}:8095/ws';
118118
_logger.log('Using port 8095 for unsecure connection: $connectionUrl');
119119
} else {
120-
// Secure connection without custom port - omit port for Cloudflare compatibility
121-
connectionUrl = '${uri.scheme}://${uri.host}/ws';
122-
_logger.log('Using implicit port for secure connection: $connectionUrl');
120+
// Secure connection - MUST include port 443 explicitly to avoid port :0
121+
connectionUrl = '${uri.scheme}://${uri.host}:443/ws';
122+
_logger.log('Using explicit port 443 for secure connection: $connectionUrl');
123123
}
124124

125125
// Connect using native WebSocket with custom headers

0 commit comments

Comments
 (0)