Ejemplo n.º 1
0
        private async void OnNewMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            if (_userSocket == null)
            {
                _logger.LogWarning("No connected socket for current message");
                return;
            }

            if (!_userSocket.CloseStatus.HasValue)
            {
                var body = e.GetBytes();
                await _userSocket.SendAsync(body, WebSocketMessageType.Binary, true, _cancellationTokenSource.Token).ConfigureAwait(false);

                return;
            }

            _logger.LogInformation("Client socket was closed");
            _cancellationTokenSource?.Cancel();
        }