Exemple #1
0
        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>();
            ((IJSInProcessRuntime)JSRuntime.Current).Invoke <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();
        }
Exemple #2
0
        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);
        }