public override async Task OnConnectedAsync(HubConnectionContext connection) { await _wrappedHubLifetimeManager.OnConnectedAsync(connection); _connections.Add(connection); await _userTracker.AddUser(connection, new UserDetails(connection.ConnectionId, connection.User.Identity.Name)); }
public override async Task OnConnectedAsync(HubConnectionContext connection) { await _wrappedHubLifetimeManager.OnConnectedAsync(connection); _connections.Add(connection); var httpContext = connection.GetHttpContext(); var role = httpContext.User?.FindFirstValue(ClaimTypes.Role) ?? ""; var email = httpContext.User?.FindFirst(ClaimTypes.Email).Value ?? ""; var livechatId = httpContext.User?.FindFirstValue("LivechatUserId") ?? ""; var authToken = httpContext.User?.FindFirstValue("AuthToken") ?? ""; var device = httpContext.User?.FindFirstValue("Device") ?? ""; var version = httpContext.User?.FindFirstValue("Version") ?? ""; var nopCustomerId = int.Parse(httpContext.User?.FindFirstValue("CustomerId") ?? "0"); var agentStores = httpContext.User?.FindFirstValue("Stores"); var storesParsed = string.IsNullOrEmpty(agentStores) ? new List <int>() : agentStores? .Split(',')? .Select(t => int.Parse(t))? .ToList() ?? new List <int>(); var userPayloadString = httpContext.User?.FindFirstValue("UserPayload") ?? ""; var userPayload = new Dictionary <string, object>(); // StoreId from livechat user var customerStoreIdHeader = httpContext.Request.Headers["storeId"]; if (!int.TryParse(customerStoreIdHeader, out var customerStoreId)) { customerStoreId = 0; } if (!string.IsNullOrEmpty(userPayloadString)) { userPayload = JsonConvert.DeserializeObject <Dictionary <string, object> >(userPayloadString); } await _userTracker.AddUser ( connection, new UserDetails ( connection.ConnectionId, connection.User.Identity.Name ) { LivechatUserId = livechatId, Role = role, Stores = storesParsed, Email = email, CustomerStoreId = customerStoreId, Payload = userPayload, CustomerId = nopCustomerId, AuthToken = authToken, Device = device, Version = version } ); }
public override async Task OnConnectedAsync(HubConnectionContext connection) { await _wrappedHubLifetimeManager.OnConnectedAsync(connection); _connections.Add(connection); var user = new UserDetails(connection.ConnectionId, connection.UserIdentifier, connection.UserId() ?? 0); await _userTracker.AddUser(connection, user); }
/// <inheritdoc /> public override async Task OnConnectedAsync(ConnectionContext connection) { // We check to see if HubOptions<THub> are set because those take precedence over global hub options. // Then set the keepAlive and handshakeTimeout values to the defaults in HubOptionsSetup when they were explicitly set to null. var supportedProtocols = _hubOptions.SupportedProtocols ?? _globalHubOptions.SupportedProtocols; if (supportedProtocols == null || supportedProtocols.Count == 0) { throw new InvalidOperationException("There are no supported protocols"); } var handshakeTimeout = _hubOptions.HandshakeTimeout ?? _globalHubOptions.HandshakeTimeout ?? HubOptionsSetup.DefaultHandshakeTimeout; var contextOptions = new HubConnectionContextOptions() { KeepAliveInterval = _hubOptions.KeepAliveInterval ?? _globalHubOptions.KeepAliveInterval ?? HubOptionsSetup.DefaultKeepAliveInterval, ClientTimeoutInterval = _hubOptions.ClientTimeoutInterval ?? _globalHubOptions.ClientTimeoutInterval ?? HubOptionsSetup.DefaultClientTimeoutInterval, StreamBufferCapacity = _hubOptions.StreamBufferCapacity ?? _globalHubOptions.StreamBufferCapacity ?? HubOptionsSetup.DefaultStreamBufferCapacity, MaximumReceiveMessageSize = _maximumMessageSize, SystemClock = SystemClock, MaximumParallelInvocations = _maxParallelInvokes, }; Log.ConnectedStarting(_logger); var connectionContext = new HubConnectionContext(connection, contextOptions, _loggerFactory); var resolvedSupportedProtocols = (supportedProtocols as IReadOnlyList <string>) ?? supportedProtocols.ToList(); if (!await connectionContext.HandshakeAsync(handshakeTimeout, resolvedSupportedProtocols, _protocolResolver, _userIdProvider, _enableDetailedErrors)) { return; } // -- the connectionContext has been set up -- try { await _lifetimeManager.OnConnectedAsync(connectionContext); await RunHubAsync(connectionContext); } finally { connectionContext.Cleanup(); Log.ConnectedEnding(_logger); await _lifetimeManager.OnDisconnectedAsync(connectionContext); } }