aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
diff options
context:
space:
mode:
author7illusions <z@7illusions.com>2014-08-30 19:06:58 +0200
committer7illusions <z@7illusions.com>2014-08-30 19:06:58 +0200
commit66ad1699e22029b605e17735e8d9450285d8748a (patch)
treeffc92c88d24850b2f82b6b3a8bdd904a2ccc77a5 /MediaBrowser.Server.Implementations/Session/WebSocketController.cs
parent34bc54263e886aae777a3537dc50a6535b51330a (diff)
parent9d36f518182bc075c19d78084870f5115fa62d1e (diff)
Merge pull request #1 from MediaBrowser/master
Update to latest
Diffstat (limited to 'MediaBrowser.Server.Implementations/Session/WebSocketController.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Session/WebSocketController.cs51
1 files changed, 45 insertions, 6 deletions
diff --git a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
index 5fc28e81b..2d5a30f3d 100644
--- a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
+++ b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
@@ -62,14 +62,28 @@ namespace MediaBrowser.Server.Implementations.Session
void connection_Closed(object sender, EventArgs e)
{
- var capabilities = new SessionCapabilities
+ if (!GetActiveSockets().Any())
{
- PlayableMediaTypes = Session.PlayableMediaTypes,
- SupportedCommands = Session.SupportedCommands,
- SupportsMediaControl = SupportsMediaControl
- };
+ try
+ {
+ _sessionManager.ReportSessionEnded(Session.Id);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error reporting session ended.", ex);
+ }
+ }
+ else
+ {
+ var capabilities = new SessionCapabilities
+ {
+ PlayableMediaTypes = Session.PlayableMediaTypes,
+ SupportedCommands = Session.SupportedCommands,
+ SupportsMediaControl = SupportsMediaControl
+ };
- _sessionManager.ReportCapabilities(Session.Id, capabilities);
+ _sessionManager.ReportCapabilities(Session.Id, capabilities);
+ }
}
private IWebSocketConnection GetActiveSocket()
@@ -220,6 +234,8 @@ namespace MediaBrowser.Server.Implementations.Session
private Task SendMessage<T>(WebSocketMessage<T> message, CancellationToken cancellationToken)
{
+ if (SkipSending()) return Task.FromResult(true);
+
var socket = GetActiveSocket();
return socket.SendAsync(message, cancellationToken);
@@ -227,6 +243,8 @@ namespace MediaBrowser.Server.Implementations.Session
private Task SendMessages<T>(WebSocketMessage<T> message, CancellationToken cancellationToken)
{
+ if (SkipSending()) return Task.FromResult(true);
+
var tasks = GetActiveSockets().Select(i => Task.Run(async () =>
{
try
@@ -243,6 +261,27 @@ 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())