public Task StartAsync(Uri url, TransferFormat transferFormat) { if (transferFormat != TransferFormat.Text) { throw new ArgumentException( $"The '{transferFormat}' transfer format is not supported by this transport.", nameof(transferFormat)); } Log.StartTransport(_logger, transferFormat); // Create pipe PipeOptions options = ClientPipeOptions.DefaultOptions; DuplexPipe.DuplexPipePair pair = DuplexPipe.CreateConnectionPair(options, options); _transport = pair.Transport; _application = pair.Application; CancellationTokenSource inputCts = new CancellationTokenSource(); _application.Input.OnWriterCompleted((exception, state) => ((CancellationTokenSource)state).Cancel(), inputCts); // Start streams Running = ProcessAsync(url, inputCts.Token); return(Task.CompletedTask); }
public async Task StartAsync(Uri url, TransferFormat transferFormat) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (transferFormat != TransferFormat.Binary && transferFormat != TransferFormat.Text) { throw new ArgumentException( $"The '{transferFormat}' transfer format is not supported by this transport.", nameof(transferFormat)); } Log.StartTransport(_logger, transferFormat); // Create connection _startTask = new TaskCompletionSource <object>(); await _jsRuntime.InvokeAsync <object>( "BlazorSignalR.WebSocketsTransport.CreateConnection", url.ToString(), transferFormat == TransferFormat.Binary, new DotNetObjectRef(this)); await _startTask.Task; _startTask = null; Log.StartedTransport(_logger); // Create the pipe pair (Application's writer is connected to Transport's reader, and vice versa) PipeOptions options = ClientPipeOptions.DefaultOptions; DuplexPipe.DuplexPipePair pair = DuplexPipe.CreateConnectionPair(options, options); _transport = pair.Transport; _application = pair.Application; Running = ProcessSocketAsync(); }
public Task StartAsync(Uri url, TransferFormat transferFormat, CancellationToken cancellationToken) { if (transferFormat != TransferFormat.Text) { throw new ArgumentException( $"The '{transferFormat}' transfer format is not supported by this transport.", nameof(transferFormat)); } Log.StartTransport(_logger, transferFormat); // Create pipe PipeOptions options = ClientPipeOptions.DefaultOptions; DuplexPipe.DuplexPipePair pair = DuplexPipe.CreateConnectionPair(options, options); _transport = pair.Transport; _application = pair.Application; // Start streams Running = ProcessAsync(url, default); return(Task.CompletedTask); }