aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-11 12:41:50 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-11 12:41:50 -0400
commita1b45e98904c287b82d2f7d24eb4f4e2a248e211 (patch)
treeecb6baa9b12bc7cbbcf92d86ba2457de437cfef5
parent369107bab8f7ede2a3350249ee0cf83ba57cf81b (diff)
fixed web socket check-ins
-rw-r--r--MediaBrowser.Api/SessionsService.cs11
-rw-r--r--MediaBrowser.Controller/Session/SessionInfo.cs17
-rw-r--r--MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs14
3 files changed, 28 insertions, 14 deletions
diff --git a/MediaBrowser.Api/SessionsService.cs b/MediaBrowser.Api/SessionsService.cs
index 271e5bbd6..eae5d6d6a 100644
--- a/MediaBrowser.Api/SessionsService.cs
+++ b/MediaBrowser.Api/SessionsService.cs
@@ -98,12 +98,15 @@ namespace MediaBrowser.Api
throw new ResourceNotFoundException(string.Format("Session {0} not found.", request.Id));
}
- session.WebSocket.SendAsync(new WebSocketMessage<BrowseTo>
+ foreach (var socket in session.WebSockets)
{
- MessageType = "Browse",
- Data = request
+ socket.SendAsync(new WebSocketMessage<BrowseTo>
+ {
+ MessageType = "Browse",
+ Data = request
- }, CancellationToken.None);
+ }, CancellationToken.None);
+ }
}
}
}
diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs
index 93ef4f694..c9ed47756 100644
--- a/MediaBrowser.Controller/Session/SessionInfo.cs
+++ b/MediaBrowser.Controller/Session/SessionInfo.cs
@@ -1,4 +1,6 @@
-using MediaBrowser.Common.Net;
+using System.Collections.Generic;
+using System.Linq;
+using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Net;
using System;
@@ -10,6 +12,11 @@ namespace MediaBrowser.Controller.Session
/// </summary>
public class SessionInfo
{
+ public SessionInfo()
+ {
+ WebSockets = new List<IWebSocketConnection>();
+ }
+
/// <summary>
/// Gets or sets the id.
/// </summary>
@@ -86,7 +93,7 @@ namespace MediaBrowser.Controller.Session
/// Gets or sets the web socket.
/// </summary>
/// <value>The web socket.</value>
- public IWebSocketConnection WebSocket { get; set; }
+ public List<IWebSocketConnection> WebSockets { get; set; }
/// <summary>
/// Gets a value indicating whether this instance is active.
@@ -96,9 +103,9 @@ namespace MediaBrowser.Controller.Session
{
get
{
- if (WebSocket != null)
+ if (WebSockets.Count > 0)
{
- return WebSocket.State == WebSocketState.Open;
+ return WebSockets.Any(i => i.State == WebSocketState.Open);
}
return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 5;
@@ -113,7 +120,7 @@ namespace MediaBrowser.Controller.Session
{
get
{
- return WebSocket != null && WebSocket.State == WebSocketState.Open;
+ return WebSockets.Any(i => i.State == WebSocketState.Open);
}
}
}
diff --git a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs
index ed1280ea9..19d177a94 100644
--- a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs
+++ b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs
@@ -7,6 +7,7 @@ using MediaBrowser.Model.Logging;
using System;
using System.Linq;
using System.Threading.Tasks;
+using MediaBrowser.Model.Net;
namespace MediaBrowser.Server.Implementations.Session
{
@@ -66,12 +67,15 @@ namespace MediaBrowser.Server.Implementations.Session
if (session != null)
{
- session.WebSocket = message.Connection;
+ var sockets = session.WebSockets.Where(i => i.State == WebSocketState.Open).ToList();
+ sockets.Add(message.Connection);
+
+ session.WebSockets = sockets;
}
}
else if (string.Equals(message.MessageType, "Context", StringComparison.OrdinalIgnoreCase))
{
- var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSocket == message.Connection);
+ var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
if (session != null)
{
@@ -84,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.Session
}
else if (string.Equals(message.MessageType, "PlaybackStart", StringComparison.OrdinalIgnoreCase))
{
- var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSocket == message.Connection);
+ var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
if (session != null && session.UserId.HasValue)
{
@@ -95,7 +99,7 @@ namespace MediaBrowser.Server.Implementations.Session
}
else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase))
{
- var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSocket == message.Connection);
+ var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
if (session != null && session.UserId.HasValue)
{
@@ -122,7 +126,7 @@ namespace MediaBrowser.Server.Implementations.Session
}
else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase))
{
- var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSocket == message.Connection);
+ var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
if (session != null && session.UserId.HasValue)
{