diff options
| author | Luke <luke.pulverenti@gmail.com> | 2015-03-25 00:59:49 -0400 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2015-03-25 00:59:49 -0400 |
| commit | aa079120059699f4778d80f55e68883d75d26b3a (patch) | |
| tree | 90ef957908152d11333fde96b95d609309560bb2 /MediaBrowser.Server.Implementations/Session/WebSocketController.cs | |
| parent | 9926be0d9de688c04065c916e44ada4177b38a80 (diff) | |
| parent | 29b6ee4b6f336f08807a7ed7bdb22a1ef68269c0 (diff) | |
Merge pull request #1051 from MediaBrowser/dev
3.0.5557.20000 Beta
Diffstat (limited to 'MediaBrowser.Server.Implementations/Session/WebSocketController.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Session/WebSocketController.cs | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs index 19aaaf8a5..765664299 100644 --- a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs +++ b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs @@ -30,17 +30,36 @@ 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; + private DateTime _lastActivityDate; public bool IsSessionActive { get { - return Sockets.Any(i => i.State == WebSocketState.Open); + if (HasOpenSockets) + { + return true; + } + + //return false; + return _isActive && (DateTime.UtcNow - _lastActivityDate).TotalMinutes <= 10; } } - public bool SupportsMediaControl + public void OnActivity() { - get { return GetActiveSockets().Any(); } + _isActive = true; + _lastActivityDate = DateTime.UtcNow; } private IEnumerable<IWebSocketConnection> GetActiveSockets() @@ -64,6 +83,8 @@ namespace MediaBrowser.Server.Implementations.Session { if (!GetActiveSockets().Any()) { + _isActive = false; + try { _sessionManager.ReportSessionEnded(Session.Id); @@ -233,8 +254,6 @@ namespace MediaBrowser.Server.Implementations.Session private Task SendMessageInternal<T>(WebSocketMessage<T> message, CancellationToken cancellationToken) { - if (SkipSending()) return Task.FromResult(true); - var socket = GetActiveSocket(); return socket.SendAsync(message, cancellationToken); @@ -242,8 +261,6 @@ namespace MediaBrowser.Server.Implementations.Session private Task SendMessagesInternal<T>(WebSocketMessage<T> message, CancellationToken cancellationToken) { - if (SkipSending()) return Task.FromResult(true); - var tasks = GetActiveSockets().Select(i => Task.Run(async () => { try @@ -260,27 +277,6 @@ namespace MediaBrowser.Server.Implementations.Session return Task.WhenAll(tasks); } - private bool SkipSending() - { - if (Session != null) - { - if (string.Equals(Session.Client, "mb-classic", StringComparison.OrdinalIgnoreCase)) - { - Version version; - - if (!string.IsNullOrWhiteSpace(Session.ApplicationVersion) && Version.TryParse(Session.ApplicationVersion, out version)) - { - if (version < new Version(3, 0, 196)) - { - _logger.Debug("Skipping web socket message to MBC version {0}.", version); - return true; - } - } - } - } - return false; - } - public void Dispose() { foreach (var socket in Sockets.ToList()) |
