Ejemplo n.º 1
0
        public async Task OnDisconnect(string reason = null)
        {
            _logger.LogDebug("Disconnecting connection on {hubName} for connection {connectionId} from server {serverId} via {reason}",
                             _keyData.HubName, _keyData.Id, State.ServerId, reason);

            if (_keyData.Id != null)
            {
                var clientDisconnectStream = _streamProvider.GetStream <string>(Constants.CLIENT_DISCONNECT_STREAM_ID, _keyData.Id);
                await clientDisconnectStream.OnNextAsync(_keyData.Id);
            }

            if (reason == ClientDisconnectReasons.HubDisconnect) // only cleanup if hub disconnects gracefully - otherwise don't so it can recover
            {
                await ClearStateAsync();
            }

            if (_serverDisconnectedStream != null)
            {
                await _serverDisconnectedStream.UnsubscribeAllSubscriptionHandlers();
            }
            DeactivateOnIdle();
        }