connect method
Implementation
@override
Future<void> connect(String? url, TransferFormat transferFormat) async {
assert(!isStringEmpty(url));
_url = url;
_logger?.finest("(LongPolling transport) Connecting");
if (transferFormat == TransferFormat.Binary) {
throw new GeneralError(
"Binary protocols via Long Polling Transport is not supported.");
}
final pollOptions = SignalRHttpRequest(
abortSignal: _pollAbort.signal,
headers: MessageHeaders(),
timeout: 100000);
final token = await _getAccessToken();
_updateHeaderToken(pollOptions, token);
// Make initial long polling request
// Server uses first long polling request to finish initializing connection and it returns without data
final pollUrl = "$_url&_=${DateTime.now()}";
_logger?.finest("(LongPolling transport) polling: $pollUrl");
final response = await _httpClient.get(pollUrl, options: pollOptions);
if (response.statusCode != 200) {
_logger?.severe(
"(LongPolling transport) Unexpected response code: ${response.statusCode}");
// Mark running as false so that the poll immediately ends and runs the close logic
_closeError = HttpError(response.statusText ?? "", response.statusCode);
_running = false;
} else {
_running = true;
}
_receiving = poll(_url, pollOptions);
}