diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-03-21 12:10:02 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-03-21 12:10:02 -0400 |
| commit | c0aec48a31d96726a6fb1814f28b6971fabca163 (patch) | |
| tree | 5ae0f4c295a722dfbc91e93d20b632d449adcf4e /MediaBrowser.Server.Implementations/Session | |
| parent | e068e84ab6c2bdee49c41ceef50cbcedd8bcb355 (diff) | |
beta fixes
Diffstat (limited to 'MediaBrowser.Server.Implementations/Session')
3 files changed, 49 insertions, 22 deletions
diff --git a/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs b/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs index 4d5c40853..9a7fb33df 100644 --- a/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs +++ b/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs @@ -43,6 +43,10 @@ namespace MediaBrowser.Server.Implementations.Session ResetPingTimer(); } + public void OnActivity() + { + } + private string PostUrl { get diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 5ea970426..f88e21aea 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -236,34 +236,44 @@ namespace MediaBrowser.Server.Implementations.Session } var activityDate = DateTime.UtcNow; - var session = await GetSessionInfo(appName, appVersion, deviceId, deviceName, remoteEndPoint, user).ConfigureAwait(false); - + var lastActivityDate = session.LastActivityDate; session.LastActivityDate = activityDate; - if (user == null) + if (user != null) { - return session; - } - - var lastActivityDate = user.LastActivityDate; + var userLastActivityDate = user.LastActivityDate ?? DateTime.MinValue; + user.LastActivityDate = activityDate; - user.LastActivityDate = activityDate; + // Don't log in the db anymore frequently than 10 seconds + if ((activityDate - userLastActivityDate).TotalSeconds > 10) + { + try + { + // Save this directly. No need to fire off all the events for this. + await _userRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false); + } + catch (Exception ex) + { + _logger.ErrorException("Error updating user", ex); + } + } + } - // Don't log in the db anymore frequently than 10 seconds - if (lastActivityDate.HasValue && (activityDate - lastActivityDate.Value).TotalSeconds < 10) + if ((activityDate - lastActivityDate).TotalSeconds > 10) { - return session; - } + EventHelper.FireEventIfNotNull(SessionActivity, this, new SessionEventArgs + { + SessionInfo = session - // Save this directly. No need to fire off all the events for this. - await _userRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false); + }, _logger); + } - EventHelper.FireEventIfNotNull(SessionActivity, this, new SessionEventArgs + var controller = session.SessionController; + if (controller != null) { - SessionInfo = session - - }, _logger); + controller.OnActivity(); + } return session; } @@ -1680,7 +1690,7 @@ namespace MediaBrowser.Server.Implementations.Session deviceId = info.DeviceId; } - return GetSessionInfo(appName, appVersion, deviceId, deviceName, remoteEndpoint, user); + return LogSessionActivity(appName, appVersion, deviceId, deviceName, remoteEndpoint, user); } public Task<SessionInfo> GetSessionByAuthenticationToken(string token, string deviceId, string remoteEndpoint) diff --git a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs index f51998fea..d4ecd9572 100644 --- a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs +++ b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs @@ -30,17 +30,28 @@ namespace MediaBrowser.Server.Implementations.Session Sockets = new List<IWebSocketConnection>(); } + private bool HasOpenSockets + { + get { return GetActiveSockets().Any(); } + } + + public bool SupportsMediaControl + { + get { return HasOpenSockets; } + } + + private bool _isActive; public bool IsSessionActive { get { - return Sockets.Any(i => i.State == WebSocketState.Open); + return _isActive; } } - public bool SupportsMediaControl + public void OnActivity() { - get { return GetActiveSockets().Any(); } + _isActive = true; } private IEnumerable<IWebSocketConnection> GetActiveSockets() @@ -64,6 +75,8 @@ namespace MediaBrowser.Server.Implementations.Session { if (!GetActiveSockets().Any()) { + _isActive = false; + try { _sessionManager.ReportSessionEnded(Session.Id); |
