Пример #1
0
        private async Task ConnectAsync(HttpRequest httpRequest, IBot bot, CancellationToken cancellationToken)
        {
            Logger.LogInformation($"Received request for web socket connect.");

            // Grab the auth header from the inbound http request
            var authHeader = httpRequest.Headers["Authorization"];

            // Grab the channelId which should be in the http headers
            var channelIdHeader = httpRequest.Headers["channelid"];

            var authenticationRequestResult = await BotFrameworkAuthentication.AuthenticateStreamingRequestAsync(authHeader, channelIdHeader, cancellationToken).ConfigureAwait(false);

            var connectionId = Guid.NewGuid();

            using (var scope = Logger.BeginScope(connectionId))
            {
                var socket = await httpRequest.HttpContext.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false);

                var connection = CreateWebSocketConnection(socket, Logger);

                using (var streamingActivityProcessor = new StreamingActivityProcessor(authenticationRequestResult, connection, this, bot))
                {
                    // Start receiving activities on the socket
                    _streamingConnections.TryAdd(connectionId, streamingActivityProcessor);
                    Log.WebSocketConnectionStarted(Logger);
                    await streamingActivityProcessor.ListenAsync(cancellationToken).ConfigureAwait(false);

                    _streamingConnections.TryRemove(connectionId, out _);
                    Log.WebSocketConnectionCompleted(Logger);
                }
            }
        }
        private async Task ConnectAsync(HttpRequest httpRequest, IBot bot, CancellationToken cancellationToken)
        {
            Logger.LogInformation($"Received request for web socket connect.");

            // Grab the auth header from the inbound http request
            var authHeader = httpRequest.Headers["Authorization"];

            // Grab the channelId which should be in the http headers
            var channelIdHeader = httpRequest.Headers["channelid"];

            var authenticationRequestResult = await BotFrameworkAuthentication.AuthenticateStreamingRequestAsync(authHeader, channelIdHeader, cancellationToken).ConfigureAwait(false);

            // Transition the request to a WebSocket connection
            var socket = await httpRequest.HttpContext.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false);

            // Tie the authentication results, the socket, the adapter and the bot together to be ready to handle any inbound activities
            var streamingActivityProcessor = new StreamingActivityProcessor(authenticationRequestResult, socket, this, bot);

            // Start receiving activities on the socket
            await streamingActivityProcessor.ListenAsync().ConfigureAwait(false);
        }
Пример #3
0
 /// <inheritdoc/>
 public override Task <AuthenticateRequestResult> AuthenticateStreamingRequestAsync(string authHeader, string channelIdHeader, CancellationToken cancellationToken)
 {
     return(_inner.AuthenticateStreamingRequestAsync(authHeader, channelIdHeader, cancellationToken));
 }