connect method
Connect to the server
Implementation
@override
Future<void> connect(String url, {Map<String, String>? headers}) async {
_logger.info('HTTP: Starting connection to $url');
_logger.info('HTTP: Current connected state: $connected');
if (connected) {
_logger.info('HTTP: Already connected, skipping connection');
return;
}
final startTime = DateTime.now();
try {
_url = url;
_headers = headers ?? {};
_logger.info('HTTP: URL set to $_url');
_logger.info('HTTP: Headers: $_headers');
// Set default headers
_headers!.putIfAbsent('Content-Type', () => Constants.contentTypeJson);
_headers!.putIfAbsent('Accept', () => Constants.contentTypeJson);
_headers!.putIfAbsent('User-Agent', () => Constants.userAgent);
_logger.info('HTTP: Default headers set');
// HTTP transport is always "connected" - it just needs URL and headers
// The actual Bayeux handshake is handled by the dispatcher
updateConnectionState(true);
recordConnectTime(DateTime.now().difference(startTime).inMilliseconds);
_logger.info('HTTP: Connection established successfully');
} catch (e) {
_logger.severe('HTTP: Connection failed: $e');
emitError(FayeError.network('Failed to connect: $e'));
rethrow;
}
}