public async Task <ConnectionContext> ConnectAsync(TransferFormat transferFormat, CancellationToken cancellationToken = new CancellationToken()) { BlazorHttpConnection connection = new BlazorHttpConnection(_options, _loggerFactory); try { await connection.StartAsync(transferFormat); return(connection); } catch { await connection.DisposeAsync(); throw; } }
public async ValueTask <ConnectionContext> ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken = default) { if (endPoint == null) { throw new ArgumentNullException(nameof(endPoint)); } if (!(endPoint is UriEndPoint uriEndPoint)) { throw new NotSupportedException($"The provided {nameof(EndPoint)} must be of type {nameof(UriEndPoint)}."); } if (_options.Url != null && _options.Url != uriEndPoint.Uri) { throw new InvalidOperationException($"If {nameof(BlazorHttpConnectionOptions)}.{nameof(BlazorHttpConnectionOptions.Url)} was set, it must match the {nameof(UriEndPoint)}.{nameof(UriEndPoint.Uri)} passed to {nameof(ConnectAsync)}."); } var shallowCopiedOptions = ShallowCopyHttpConnectionOptions(_options); shallowCopiedOptions.Url = uriEndPoint.Uri; var connection = new BlazorHttpConnection(shallowCopiedOptions, _jsRuntime, _loggerFactory, _navigationManager); try { await connection.StartAsync(); return(connection); } catch { await connection.DisposeAsync(); throw; } }