import 'package:flutter/foundation.dart'; /// The websocket endpoint the web build offers by default: the page's own /// origin, upgraded to ws/wss, at the server's `/connect` path. /// /// The web client is served by a same-origin proxy, so this is a configurable /// starting value, not a baked host: it is derived from the page the operator /// actually loaded. Native builds have no such origin and start blank, so no /// server host or production endpoint is compiled into the app. /// /// `web` and `base` are injectable only so the rule can be tested without a /// browser; production callers use the platform defaults. String defaultServerUrl({bool? web, Uri? base}) { if (!(web ?? kIsWeb)) return ''; final origin = base ?? Uri.base; if (origin.host.isEmpty) return ''; final secure = origin.scheme.toLowerCase() == 'https'; return Uri( scheme: secure ? 'wss' : 'ws', host: origin.host, port: origin.hasPort ? origin.port : null, path: '/connect', ).toString(); }