Beispiel #1
0
        public async Task Invoke(HttpContext context, IAudioSocket audio)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (audio == null)
            {
                throw new ArgumentNullException(nameof(audio));
            }

            if (context.WebSockets.IsWebSocketRequest)
            {
                var conversationId = context.Request.Headers["ConversationId"].ToString();
                var speaker        = context.Request.Headers["SpeakerType"].ToString();
                var speakerType    = (SpeakerType)Enum.Parse(typeof(SpeakerType), speaker);

                using var socket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(true);

                await audio.ReceiveAsync(socket, conversationId, speakerType).ConfigureAwait(false);
            }
            else
            {
                await next(context).ConfigureAwait(false);
            }
        }