start method
Implementation
Future<int> start({
int port = 9090,
String host = '0.0.0.0',
int maxRetries = 0,
bool openDashboard = false,
bool autoAdbForward = true,
}) async {
if (_server != null) return _port;
_port = port;
NeuronDebugRegistry.instance.enable();
final router = NeuronDebugRouter(NeuronDebugRegistry.instance);
final handler = const Pipeline()
.addMiddleware(logRequests())
.addMiddleware(_cors())
.addHandler(router.handler);
final address = InternetAddress(host);
for (int attempt = 0; attempt <= maxRetries; attempt++) {
final candidatePort = port + attempt;
try {
_server = await HttpServer.bind(address, candidatePort);
_port = candidatePort;
break;
} on SocketException {
if (attempt == maxRetries) rethrow;
}
}
_subscription = NeuronDebugStream.instance.stream.listen(_broadcastEvent);
_heartbeat =
Timer.periodic(const Duration(seconds: 15), (_) => _sendHeartbeat());
_server!.listen((HttpRequest request) {
if (WebSocketTransformer.isUpgradeRequest(request)) {
_handleWebSocket(request);
return;
}
shelf_io.handleRequest(request, handler);
});
// Auto-setup ADB port forwarding for Android development
if (autoAdbForward) {
await _setupAdbForward(_port);
}
if (openDashboard) {
_launchDashboard(host, _port);
}
return _port;
}