import 'dart:async'; import 'dart:io'; class ServiceCheckResult { const ServiceCheckResult({ required this.nativeCoreLoaded, required this.localSignalingRunning, required this.signalingReachable, required this.listenerRunning, required this.listenerReachable, required this.signalingUrl, required this.listenerHost, required this.listenerPort, }); final bool nativeCoreLoaded; final bool localSignalingRunning; final bool signalingReachable; final bool listenerRunning; final bool listenerReachable; final String signalingUrl; final String listenerHost; final int listenerPort; } class ServiceChecker { static Future checkSignaling( String url, { Duration timeout = const Duration(seconds: 2), }) async { final trimmed = url.trim(); if (trimmed.isEmpty) return false; final client = HttpClient()..connectionTimeout = timeout; try { final base = Uri.parse(trimmed); final path = base.path.endsWith('/') ? '${base.path}healthz' : '${base.path}/healthz'; final request = await client.getUrl(base.replace(path: path)).timeout(timeout); final response = await request.close().timeout(timeout); await response.drain().timeout(timeout); return response.statusCode == HttpStatus.ok; } on Object { return false; } finally { client.close(force: true); } } static Future checkTcp( String host, int port, { Duration timeout = const Duration(seconds: 2), }) async { try { final socket = await Socket.connect(host, port, timeout: timeout); socket.destroy(); return true; } on Object { return false; } } }