LAN discovery: server advertises _pipelines._tcp over mDNS; app finds servers on the connect screen

Server: internal/discovery publishes a DNS-SD record (hashicorp/mdns) with
the port LAN clients dial (the web proxy via -mdns-port, which the
supervisor passes, or a non-loopback -addr) and TXT v, name, path, tls, auth.
On by default; -mdns=false or PIPELINES_MDNS=off disables it. Failures are
logged and never block startup; the advert is withdrawn on shutdown.

App: the Connect to Pipelines screen gets 'Find servers on this network'
behind a ServerDiscovery interface (Bonsoir: Android NSD with multicast lock,
iOS Bonjour with NSLocalNetworkUsageDescription and NSBonjourServices).
Tapping a server fills the address and connects; manual entry stays. Web has
no scan.
This commit is contained in:
2026-11-03 14:54:54 +00:00
parent 97509cb49f
commit 7ecc12b747
22 changed files with 1174 additions and 25 deletions
+6 -1
View File
@@ -12,8 +12,13 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<!-- "Find servers on this network" browses _pipelines._tcp with NSD;
Wi-Fi drops multicast without a multicast lock, held only while a
scan runs (lib/features/onboarding/discovery/). -->
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<!-- Explicit ws:// LAN/VPN profiles are supported; no automatic TLS
downgrade or discovery is performed. Settings warns about cleartext. -->
downgrade is performed; a discovered server is only dialled when the
user taps it. Settings warns about cleartext. -->
<application
android:label="Pipelines"
android:name="${applicationName}"
+6
View File
@@ -15,6 +15,12 @@
</array>
</dict>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>Pipelines looks for Pipelines servers on your local network so you can connect without typing an address.</string>
<key>NSBonjourServices</key>
<array>
<string>_pipelines._tcp</string>
</array>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
+2
View File
@@ -9,6 +9,7 @@ import '../core/servers/server_catalog.dart';
import '../core/servers/server_catalog_store.dart';
import '../core/servers/server_probe.dart';
import '../core/transport/pipelines_client.dart';
import '../features/onboarding/discovery/server_discovery.dart';
import '../features/onboarding/onboarding_flow.dart';
import '../features/settings/server_connections.dart';
import '../features/settings/saved_servers_section.dart';
@@ -288,6 +289,7 @@ class _PipelinesRootState extends State<PipelinesRoot> {
saveServer: _saveOnboardingServer,
onDone: _done,
savedServers: SavedServersSection(connections: _servers),
discovery: platformServerDiscovery(web: widget.web),
serverAddresses:
_servers.catalog.active?.endpoints.map(Uri.parse).toList() ??
const [],
@@ -0,0 +1,85 @@
import 'dart:async';
import 'package:bonsoir/bonsoir.dart';
import 'discovered_server.dart';
import 'server_discovery.dart';
/// DNS-SD browsing through the platform service: Android NSD (Bonsoir holds
/// the Wi-Fi multicast lock while browsing) and Apple's Network framework
/// (needs NSLocalNetworkUsageDescription and NSBonjourServices).
class BonsoirServerDiscovery implements ServerDiscovery {
BonsoirServerDiscovery({this.type = pipelinesServiceType});
final String type;
@override
Stream<List<DiscoveredServer>> scan() {
late final StreamController<List<DiscoveredServer>> controller;
BonsoirDiscovery? discovery;
StreamSubscription<BonsoirDiscoveryEvent>? events;
final found = <String, DiscoveredServer>{};
void publish() {
if (!controller.isClosed) controller.add(found.values.toList());
}
Future<void> start() async {
try {
final browser = BonsoirDiscovery(type: type);
discovery = browser;
await browser.initialize();
if (controller.isClosed) return;
events = browser.eventStream?.listen(
(event) {
switch (event) {
case BonsoirDiscoveryServiceFoundEvent(:final service):
unawaited(service.resolve(browser.serviceResolver));
case BonsoirDiscoveryServiceResolvedEvent(:final service) ||
BonsoirDiscoveryServiceUpdatedEvent(:final service):
final server = DiscoveredServer.fromRecord(
instance: service.name,
addresses: service.hostAddresses,
hostname: service.hostname,
port: service.port,
attributes: service.attributes,
);
if (server != null) {
found[service.name] = server;
publish();
}
case BonsoirDiscoveryServiceLostEvent(:final service):
if (found.remove(service.name) != null) publish();
default:
break;
}
},
onError: (Object error) {
if (!controller.isClosed) controller.addError(error);
},
);
await browser.start();
publish();
} catch (error, stack) {
if (!controller.isClosed) controller.addError(error, stack);
}
}
controller = StreamController<List<DiscoveredServer>>(
onListen: () => unawaited(start()),
onCancel: () async {
await events?.cancel();
final browser = discovery;
if (browser != null && !browser.isStopped) {
try {
await browser.stop();
} catch (_) {
// Already stopped by the platform; nothing else to release.
}
}
await controller.close();
},
);
return controller.stream;
}
}
@@ -0,0 +1,109 @@
/// The DNS-SD service type the server advertises (internal/discovery).
const pipelinesServiceType = '_pipelines._tcp';
/// A Pipelines server found on the local network.
class DiscoveredServer {
const DiscoveredServer({
required this.name,
required this.host,
required this.port,
this.secure = false,
this.path = '/connect',
this.passwordRequired = true,
this.version,
});
/// Builds a server from a resolved DNS-SD record: the service [instance]
/// name, the resolved [addresses] (and SRV [hostname] when no address is
/// usable), the SRV [port] and the TXT [attributes]. Returns null when there
/// is nothing to dial.
static DiscoveredServer? fromRecord({
required String instance,
required List<String> addresses,
String? hostname,
required int port,
Map<String, String> attributes = const {},
}) {
final host = preferredHost(addresses) ?? _bare(hostname);
if (host == null || port <= 0 || port > 65535) return null;
final path = attributes['path'] ?? '';
final name = attributes['name'] ?? '';
return DiscoveredServer(
name: name.isEmpty ? instance : name,
host: host,
port: port,
secure: attributes['tls'] == '1',
path: path.startsWith('/') ? path : '/connect',
passwordRequired: attributes['auth'] != 'none',
version: attributes['v'],
);
}
final String name;
final String host;
final int port;
final bool secure;
final String path;
final bool passwordRequired;
final String? version;
/// The websocket endpoint the connect screen dials.
Uri get endpoint =>
Uri(scheme: secure ? 'wss' : 'ws', host: host, port: port, path: path);
/// "host:port" as shown under the name.
String get address => endpoint.authority;
/// Picks the address a phone can dial: IPv4 first, then a routable IPv6
/// address. Link-local IPv6 needs a zone the URL cannot carry.
static String? preferredHost(List<String> addresses) {
final values = [for (final value in addresses) value.trim()];
for (final value in values) {
final bytes = _ipv4(value);
if (bytes != null && bytes[0] != 127) return value;
}
for (final value in values) {
final bytes = _ipv6(value);
if (bytes == null) continue;
final loopback =
bytes.sublist(0, 15).every((byte) => byte == 0) && bytes[15] == 1;
final linkLocal = bytes[0] == 0xfe && (bytes[1] & 0xc0) == 0x80;
if (!loopback && !linkLocal) return value;
}
return null;
}
static List<int>? _ipv4(String value) {
if (!RegExp(r'^\d{1,3}(\.\d{1,3}){3}$').hasMatch(value)) return null;
try {
return Uri.parseIPv4Address(value);
} on FormatException {
return null;
}
}
static List<int>? _ipv6(String value) {
if (!value.contains(':') || value.contains('%')) return null;
try {
return Uri.parseIPv6Address(value);
} on FormatException {
return null;
}
}
static String? _bare(String? hostname) {
final value = hostname?.trim().replaceFirst(RegExp(r'\.$'), '') ?? '';
return value.isEmpty ? null : value;
}
@override
bool operator ==(Object other) =>
other is DiscoveredServer &&
other.name == name &&
other.endpoint == endpoint &&
other.passwordRequired == passwordRequired &&
other.version == version;
@override
int get hashCode => Object.hash(name, endpoint, passwordRequired, version);
}
@@ -0,0 +1,197 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import 'discovered_server.dart';
import 'server_discovery.dart';
enum _Phase { idle, scanning, done, failed }
/// "Find servers on this network": browses for a while, lists what answered
/// and hands a tapped server to [onSelect]. Manual entry stays beside it.
class DiscoveryPanel extends StatefulWidget {
const DiscoveryPanel({
super.key,
required this.discovery,
required this.onSelect,
this.enabled = true,
this.scanFor = const Duration(seconds: 8),
});
final ServerDiscovery discovery;
final ValueChanged<DiscoveredServer> onSelect;
final bool enabled;
/// How long one scan browses before it settles on its results.
final Duration scanFor;
@override
State<DiscoveryPanel> createState() => _DiscoveryPanelState();
}
class _DiscoveryPanelState extends State<DiscoveryPanel> {
_Phase _phase = _Phase.idle;
List<DiscoveredServer> _servers = const [];
String? _error;
StreamSubscription<List<DiscoveredServer>>? _scan;
Timer? _timer;
@override
void dispose() {
_stop();
super.dispose();
}
void _stop() {
_timer?.cancel();
_timer = null;
unawaited(_scan?.cancel());
_scan = null;
}
void _start() {
_stop();
setState(() {
_phase = _Phase.scanning;
_servers = const [];
_error = null;
});
_scan = widget.discovery.scan().listen(
(servers) {
if (mounted) setState(() => _servers = servers);
},
onError: (Object error) {
_stop();
if (mounted) {
setState(() {
_phase = _Phase.failed;
_error = '$error';
});
}
},
);
_timer = Timer(widget.scanFor, () {
_stop();
if (mounted) setState(() => _phase = _Phase.done);
});
}
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final scanning = _phase == _Phase.scanning;
final label = _phase == _Phase.idle
? 'Find servers on this network'
: 'Search again';
final enabled = widget.enabled && !scanning;
final button = cupertino
? CupertinoButton(
key: const Key('discovery-scan'),
onPressed: enabled ? _start : null,
child: Text(label),
)
: OutlinedButton.icon(
key: const Key('discovery-scan'),
onPressed: enabled ? _start : null,
icon: const Icon(Icons.wifi_find),
label: Text(label),
);
final status = switch (_phase) {
_Phase.scanning => _status(
context,
cupertino,
const Key('discovery-scanning'),
'Looking for Pipelines servers…',
busy: true,
),
_Phase.done when _servers.isEmpty => _status(
context,
cupertino,
const Key('discovery-empty'),
'No Pipelines servers answered on this network. '
'Enter the address instead.',
),
_Phase.failed => _status(
context,
cupertino,
const Key('discovery-error'),
'Could not search this network: $_error',
error: true,
),
_ => null,
};
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
button,
?status,
for (final server in _servers) _row(context, cupertino, server),
],
);
}
Widget _status(
BuildContext context,
bool cupertino,
Key key,
String text, {
bool busy = false,
bool error = false,
}) {
final color = !error
? null
: cupertino
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error;
return Padding(
key: key,
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
if (busy) ...[
cupertino
? const CupertinoActivityIndicator()
: const SizedBox.square(
dimension: 16,
child: CircularProgressIndicator(strokeWidth: 2),
),
const SizedBox(width: 12),
],
Expanded(
child: Text(text, style: TextStyle(color: color)),
),
],
),
);
}
Widget _row(BuildContext context, bool cupertino, DiscoveredServer server) {
final key = Key('discovered-${server.address}');
final subtitle = Text(
server.passwordRequired ? '${server.address} · password' : server.address,
);
void tap() => widget.onSelect(server);
final onTap = widget.enabled ? tap : null;
if (cupertino) {
return CupertinoListTile(
key: key,
leading: const Icon(CupertinoIcons.desktopcomputer),
title: Text(server.name),
subtitle: subtitle,
trailing: const CupertinoListTileChevron(),
onTap: onTap,
);
}
return ListTile(
key: key,
leading: const Icon(Icons.dns_outlined),
title: Text(server.name),
subtitle: subtitle,
trailing: const Icon(Icons.chevron_right),
enabled: widget.enabled,
onTap: onTap,
);
}
}
@@ -0,0 +1,18 @@
import 'package:flutter/foundation.dart';
import 'bonsoir_server_discovery.dart';
import 'discovered_server.dart';
/// Finds Pipelines servers on the local network.
abstract interface class ServerDiscovery {
/// Browses while listened to. Each event is every server currently known;
/// a failure to browse is a stream error. Cancelling stops the browse.
Stream<List<DiscoveredServer>> scan();
}
/// The discovery this platform supports, or null where there is none.
///
/// Browsers cannot send mDNS, and the web app is served by the server it
/// talks to, so web has no scan.
ServerDiscovery? platformServerDiscovery({bool web = kIsWeb}) =>
web ? null : BonsoirServerDiscovery();
@@ -5,6 +5,9 @@ import '../../core/session/server_session.dart';
import '../../core/transport/server_url.dart';
import '../../core/servers/server_probe.dart';
import '../../ui/adaptive/host.dart';
import 'discovery/discovered_server.dart';
import 'discovery/discovery_panel.dart';
import 'discovery/server_discovery.dart';
/// Reaches a server and reports what it says about this device's session.
typedef ServerCheck = Future<SessionState> Function(Uri endpoint);
@@ -25,6 +28,7 @@ class OnboardingFlow extends StatefulWidget {
this.saveServer,
this.savedServers,
this.serverAddresses = const [],
this.discovery,
});
/// Called with the signed-in server's endpoint.
@@ -41,6 +45,9 @@ class OnboardingFlow extends StatefulWidget {
final Widget? savedServers;
final List<Uri> serverAddresses;
/// LAN discovery; null hides the scan (web, or no platform support).
final ServerDiscovery? discovery;
@override
State<OnboardingFlow> createState() => _OnboardingFlowState();
}
@@ -135,6 +142,11 @@ class _OnboardingFlowState extends State<OnboardingFlow> {
});
}
void _useDiscovered(DiscoveredServer server) {
_server.text = server.endpoint.toString();
_continue();
}
Future<void> _signIn() async {
final endpoint = _endpoint;
if (endpoint == null || _password.text.isEmpty) return;
@@ -239,6 +251,14 @@ class _OnboardingFlowState extends State<OnboardingFlow> {
],
const SizedBox(height: 16),
button,
if (!_passwordStep && widget.discovery != null) ...[
const SizedBox(height: 16),
DiscoveryPanel(
discovery: widget.discovery!,
enabled: !_busy,
onSelect: _useDiscovered,
),
],
if (_passwordStep && !widget.startAtPassword) ...[
const SizedBox(height: 8),
cupertino
+52 -4
View File
@@ -25,6 +25,54 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.13.1"
bonsoir:
dependency: "direct main"
description:
name: bonsoir
sha256: "20fed01e4616e625f4bafd9007ff899d231d8d79bebc8564853fa1e3570294a6"
url: "https://pub.dev"
source: hosted
version: "7.1.5"
bonsoir_android:
dependency: transitive
description:
name: bonsoir_android
sha256: "0dda1164e826553b8ee90a3fd1aabd462d17f19348f542b95f9d5b5455e4157f"
url: "https://pub.dev"
source: hosted
version: "7.1.3"
bonsoir_darwin:
dependency: transitive
description:
name: bonsoir_darwin
sha256: "6f695a0b4465514b75fc1a457746ab6dfc10d7180f0d04810fd9512e6520df69"
url: "https://pub.dev"
source: hosted
version: "7.1.1"
bonsoir_linux:
dependency: transitive
description:
name: bonsoir_linux
sha256: "9afae7bb9509c5bd20a0ea2ca02a0f2b1ef09cca1ceb2ea288ed58a0f03d1e11"
url: "https://pub.dev"
source: hosted
version: "7.1.0"
bonsoir_platform_interface:
dependency: transitive
description:
name: bonsoir_platform_interface
sha256: "6c55c786b01ad279f675ae72cea3a885aa746e416d2e8c1f0c46e9d2c06420b0"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
bonsoir_windows:
dependency: transitive
description:
name: bonsoir_windows
sha256: aaabbb652fe68d3eb26a9b2cddefaae26cd9ca6ebe737d476ab9ed535c7c2516
url: "https://pub.dev"
source: hosted
version: "7.3.0"
boolean_selector:
dependency: transitive
description:
@@ -101,10 +149,10 @@ packages:
dependency: transitive
description:
name: dbus
sha256: f7db8504e715b835f5ebe5fe74604ccd961d504c73389a5d8e81bafc2e2f3612
sha256: a48d5da28e89bd02196e80d81ed8d7954923d00a0f4a68cc20b575038f023383
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.7.15"
fake_async:
dependency: transitive
description:
@@ -157,10 +205,10 @@ packages:
dependency: transitive
description:
name: file_picker_linux
sha256: c6562fc7d426db2fb85ea66fe2627953d2709932df5584ceaacf0aa5e39cf4da
sha256: eb00de71b123e91d3c61f389a05b8cc90f9cbe7e4c88da30ebe2f0442b281b61
url: "https://pub.dev"
source: hosted
version: "2.0.2"
version: "2.0.3"
file_picker_platform_interface:
dependency: transitive
description:
+1
View File
@@ -48,6 +48,7 @@ dependencies:
share_plus: ^13.3.1
file_picker: ^13.3.0
url_launcher: ^6.3.3
bonsoir: ^7.1.5
dev_dependencies:
flutter_test:
@@ -0,0 +1,68 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/onboarding/discovery/discovered_server.dart';
import 'package:pipelines_app/features/onboarding/discovery/server_discovery.dart';
void main() {
test('a proxied server becomes a ws endpoint that asks for a password', () {
final server = DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['fe80::1', '192.168.1.20'],
port: 8083,
attributes: {
'v': 'v1.4.0',
'name': 'box',
'path': '/connect',
'tls': '0',
'auth': 'password',
},
)!;
expect(server.name, 'box');
expect(server.endpoint, Uri.parse('ws://192.168.1.20:8083/connect'));
expect(server.address, '192.168.1.20:8083');
expect(server.passwordRequired, isTrue);
expect(server.version, 'v1.4.0');
});
test('TLS, no auth, missing TXT and IPv6-only records', () {
final secure = DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['2001:db8::5'],
port: 443,
attributes: {'tls': '1', 'auth': 'none'},
)!;
expect(secure.name, 'Pipelines-box');
expect(secure.endpoint, Uri.parse('wss://[2001:db8::5]:443/connect'));
expect(secure.passwordRequired, isFalse);
});
test('falls back to the SRV host name, and refuses nothing to dial', () {
final named = DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['fe80::1', '127.0.0.1'],
hostname: 'box.local.',
port: 8083,
)!;
expect(named.endpoint, Uri.parse('ws://box.local:8083/connect'));
expect(
DiscoveredServer.fromRecord(
instance: 'x',
addresses: const [],
port: 8083,
),
isNull,
);
expect(
DiscoveredServer.fromRecord(
instance: 'x',
addresses: ['10.0.0.2'],
port: 0,
),
isNull,
);
});
test('web has no discovery; native platforms do', () {
expect(platformServerDiscovery(web: true), isNull);
expect(platformServerDiscovery(web: false), isNotNull);
});
}
@@ -0,0 +1,164 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/session/server_session.dart';
import 'package:pipelines_app/features/onboarding/discovery/discovered_server.dart';
import 'package:pipelines_app/features/onboarding/discovery/server_discovery.dart';
import 'package:pipelines_app/features/onboarding/onboarding_flow.dart';
/// A discoverer the test drives: each scan is a controller the test feeds.
class FakeDiscovery implements ServerDiscovery {
final scans = <StreamController<List<DiscoveredServer>>>[];
int cancelled = 0;
StreamController<List<DiscoveredServer>> get current => scans.last;
@override
Stream<List<DiscoveredServer>> scan() {
final controller = StreamController<List<DiscoveredServer>>(
onCancel: () => cancelled++,
);
scans.add(controller);
return controller.stream;
}
}
const box = DiscoveredServer(name: 'box', host: '192.168.1.20', port: 8083);
const studio = DiscoveredServer(
name: 'studio',
host: '192.168.1.30',
port: 8080,
passwordRequired: false,
);
Widget host(Widget child, {bool cupertino = false}) =>
cupertino ? CupertinoApp(home: child) : MaterialApp(home: child);
void main() {
late FakeDiscovery discovery;
late List<Uri> checked;
late List<String> saved;
setUp(() {
discovery = FakeDiscovery();
checked = [];
saved = [];
});
OnboardingFlow flow({ServerDiscovery? discoverer, ValueChanged<Uri>? done}) =>
OnboardingFlow(
discovery: discoverer,
check: (uri) async {
checked.add(uri);
return SessionState.signedOut;
},
saveServer: (url) async => saved.add(url),
onDone: done ?? (_) {},
);
testWidgets('no discoverer (web) shows manual entry only', (tester) async {
await tester.pumpWidget(host(flow()));
expect(find.byKey(const Key('onboarding-server')), findsOneWidget);
expect(find.byKey(const Key('discovery-scan')), findsNothing);
});
testWidgets('scanning lists servers as they answer, then settles', (
tester,
) async {
await tester.pumpWidget(host(flow(discoverer: discovery)));
expect(find.text('Find servers on this network'), findsOneWidget);
await tester.tap(find.byKey(const Key('discovery-scan')));
await tester.pump();
expect(find.byKey(const Key('discovery-scanning')), findsOneWidget);
discovery.current.add([box]);
await tester.pump();
expect(find.text('box'), findsOneWidget);
expect(find.text('192.168.1.20:8083 · password'), findsOneWidget);
discovery.current.add([box, studio]);
await tester.pump();
expect(find.text('studio'), findsOneWidget);
expect(find.text('192.168.1.30:8080'), findsOneWidget);
await tester.pump(const Duration(seconds: 8));
expect(find.byKey(const Key('discovery-scanning')), findsNothing);
expect(discovery.cancelled, 1);
expect(find.text('box'), findsOneWidget);
expect(find.text('Search again'), findsOneWidget);
});
testWidgets('tapping a server fills the address and connects', (
tester,
) async {
await tester.pumpWidget(host(flow(discoverer: discovery)));
await tester.tap(find.byKey(const Key('discovery-scan')));
await tester.pump();
discovery.current.add([box]);
await tester.pump();
await tester.tap(find.byKey(const Key('discovered-192.168.1.20:8083')));
await tester.pumpAndSettle();
final endpoint = Uri.parse('ws://192.168.1.20:8083/connect');
expect(checked, [endpoint]);
expect(saved, [endpoint.toString()]);
// The server wants its password: the flow moved to sign-in.
expect(find.byKey(const Key('onboarding-password')), findsOneWidget);
expect(find.byKey(const Key('discovery-scan')), findsNothing);
});
testWidgets('an empty scan says so and keeps manual entry', (tester) async {
await tester.pumpWidget(host(flow(discoverer: discovery)));
await tester.tap(find.byKey(const Key('discovery-scan')));
await tester.pump();
discovery.current.add(const []);
await tester.pump(const Duration(seconds: 8));
expect(find.byKey(const Key('discovery-empty')), findsOneWidget);
expect(find.byKey(const Key('onboarding-server')), findsOneWidget);
await tester.tap(find.byKey(const Key('discovery-scan')));
await tester.pump();
expect(discovery.scans, hasLength(2));
expect(find.byKey(const Key('discovery-empty')), findsNothing);
expect(find.byKey(const Key('discovery-scanning')), findsOneWidget);
await tester.pump(const Duration(seconds: 8));
});
testWidgets('a browse failure is shown and the scan can be retried', (
tester,
) async {
await tester.pumpWidget(host(flow(discoverer: discovery)));
await tester.tap(find.byKey(const Key('discovery-scan')));
await tester.pump();
discovery.current.addError(StateError('multicast blocked'));
await tester.pump();
expect(find.byKey(const Key('discovery-error')), findsOneWidget);
expect(find.textContaining('multicast blocked'), findsOneWidget);
expect(find.byKey(const Key('discovery-scanning')), findsNothing);
// The timer was cancelled with the scan; nothing fires later.
await tester.pump(const Duration(seconds: 8));
expect(find.byKey(const Key('discovery-error')), findsOneWidget);
});
testWidgets('Cupertino host lists and connects the same way', (tester) async {
await tester.pumpWidget(host(flow(discoverer: discovery), cupertino: true));
await tester.tap(find.byKey(const Key('discovery-scan')));
await tester.pump();
discovery.current.add([studio]);
await tester.pump();
expect(find.byType(CupertinoListTile), findsOneWidget);
await tester.tap(find.byKey(const Key('discovered-192.168.1.30:8080')));
await tester.pumpAndSettle();
expect(checked, [Uri.parse('ws://192.168.1.30:8080/connect')]);
});
testWidgets('leaving the screen mid-scan stops browsing', (tester) async {
await tester.pumpWidget(host(flow(discoverer: discovery)));
await tester.tap(find.byKey(const Key('discovery-scan')));
await tester.pump();
await tester.pumpWidget(host(const SizedBox()));
expect(discovery.cancelled, 1);
});
}