connect method
void
connect(
- EventFluxConnectionType type,
- String url, {
- Map<
String, String> header = const {'Accept' : 'text/event-stream', 'Cache-Control' : 'no-store'}, - dynamic onConnectionClose()?,
- bool autoReconnect = false,
- ReconnectConfig? reconnectConfig,
- required dynamic onSuccessCallback(),
- dynamic onError()?,
- HttpClientAdapter? httpClient,
- Map<
String, dynamic> ? body, - String? tag,
- bool logReceivedData = false,
- List<
MultipartFile> ? files, - bool multipartRequest = false,
- WebConfig? webConfig,
- List<
EventFluxInterceptor> ? interceptors, - Future<
void> ? abortTrigger,
override
Implementation
@override
void connect(
EventFluxConnectionType type,
String url, {
Map<String, String> header = const {'Accept': 'text/event-stream', 'Cache-Control': 'no-store'},
Function()? onConnectionClose,
bool autoReconnect = false,
ReconnectConfig? reconnectConfig,
required Function(EventFluxResponse?) onSuccessCallback,
Function(EventFluxException)? onError,
HttpClientAdapter? httpClient,
Map<String, dynamic>? body,
String? tag,
bool logReceivedData = false,
List<MultipartFile>? files,
bool multipartRequest = false,
WebConfig? webConfig,
List<EventFluxInterceptor>? interceptors,
Future<void>? abortTrigger,
}) {
if (kIsWeb && webConfig == null) {
throw ArgumentError('WebConfig must be provided on web');
}
// This check prevents redundant connection requests when a connection is already in progress.
if (_status == EventFluxStatus.connected ||
_status == EventFluxStatus.connectionInitiated ||
_status == EventFluxStatus.reconnecting) {
eventFluxLog('Already Connection in Progress, Skipping redundant request',
LogEvent.info, _tag);
return;
}
_status = EventFluxStatus.connectionInitiated;
/// Set the tag for logging purposes.
_tag = tag;
/// If autoReconnect is enabled and reconnectConfig is not provided, log an error and return.
if (autoReconnect && reconnectConfig == null) {
eventFluxLog(
"ReconnectConfig is required when autoReconnect is enabled",
LogEvent.error,
tag,
);
return;
}
eventFluxLog("$_status", LogEvent.info, _tag);
if (reconnectConfig != null) {
_reconnectStrategy.initialize(reconnectConfig);
}
_isExplicitDisconnect = false;
final config = ConnectionConfig(
type: type,
url: url,
header: header,
autoReconnect: autoReconnect,
reconnectConfig: reconnectConfig,
onSuccessCallback: onSuccessCallback,
onError: onError,
onConnectionClose: onConnectionClose,
httpClient: httpClient,
body: body,
tag: tag,
logReceivedData: logReceivedData,
files: files,
multipartRequest: multipartRequest,
webConfig: webConfig,
interceptors: interceptors,
abortTrigger: abortTrigger,
);
_start(config);
}