aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-02 21:22:50 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-02 21:22:50 -0400
commiteb72c2db513f5306eecccb94f0f1cd5296a7d7db (patch)
treea344f75c10085a9a8f5ac57c4926dbab09161e45 /MediaBrowser.Server.Implementations/Session/WebSocketController.cs
parent33a3e215d03d2e8dad3e653e7c75258dc7eb4989 (diff)
updated nuget
Diffstat (limited to 'MediaBrowser.Server.Implementations/Session/WebSocketController.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Session/WebSocketController.cs85
1 files changed, 71 insertions, 14 deletions
diff --git a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
index fb0bc9b7c..46c8f752d 100644
--- a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
+++ b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs
@@ -1,8 +1,12 @@
using MediaBrowser.Common.Net;
+using MediaBrowser.Controller;
using MediaBrowser.Controller.Session;
+using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Session;
+using MediaBrowser.Model.System;
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -11,15 +15,39 @@ namespace MediaBrowser.Server.Implementations.Session
{
public class WebSocketController : ISessionController
{
- public bool Supports(SessionInfo session)
+ public SessionInfo Session { get; private set; }
+ public List<IWebSocketConnection> Sockets { get; private set; }
+
+ private readonly IServerApplicationHost _appHost;
+
+ public WebSocketController(SessionInfo session, IServerApplicationHost appHost)
{
- return session.WebSockets.Any(i => i.State == WebSocketState.Open);
+ Session = session;
+ _appHost = appHost;
+ Sockets = new List<IWebSocketConnection>();
}
- private IWebSocketConnection GetSocket(SessionInfo session)
+ public bool SupportsMediaRemoteControl
{
- var socket = session.WebSockets.OrderByDescending(i => i.LastActivityDate).FirstOrDefault(i => i.State == WebSocketState.Open);
+ get
+ {
+ return Sockets.Any(i => i.State == WebSocketState.Open);
+ }
+ }
+ public bool IsSessionActive
+ {
+ get
+ {
+ return Sockets.Any(i => i.State == WebSocketState.Open);
+ }
+ }
+
+ private IWebSocketConnection GetActiveSocket()
+ {
+ var socket = Sockets
+ .OrderByDescending(i => i.LastActivityDate)
+ .FirstOrDefault(i => i.State == WebSocketState.Open);
if (socket == null)
{
@@ -29,9 +57,9 @@ namespace MediaBrowser.Server.Implementations.Session
return socket;
}
- public Task SendSystemCommand(SessionInfo session, SystemCommand command, CancellationToken cancellationToken)
+ public Task SendSystemCommand(SystemCommand command, CancellationToken cancellationToken)
{
- var socket = GetSocket(session);
+ var socket = GetActiveSocket();
return socket.SendAsync(new WebSocketMessage<string>
{
@@ -41,9 +69,9 @@ namespace MediaBrowser.Server.Implementations.Session
}, cancellationToken);
}
- public Task SendMessageCommand(SessionInfo session, MessageCommand command, CancellationToken cancellationToken)
+ public Task SendMessageCommand(MessageCommand command, CancellationToken cancellationToken)
{
- var socket = GetSocket(session);
+ var socket = GetActiveSocket();
return socket.SendAsync(new WebSocketMessage<MessageCommand>
{
@@ -53,9 +81,9 @@ namespace MediaBrowser.Server.Implementations.Session
}, cancellationToken);
}
- public Task SendPlayCommand(SessionInfo session, PlayRequest command, CancellationToken cancellationToken)
+ public Task SendPlayCommand(PlayRequest command, CancellationToken cancellationToken)
{
- var socket = GetSocket(session);
+ var socket = GetActiveSocket();
return socket.SendAsync(new WebSocketMessage<PlayRequest>
{
@@ -65,9 +93,9 @@ namespace MediaBrowser.Server.Implementations.Session
}, cancellationToken);
}
- public Task SendBrowseCommand(SessionInfo session, BrowseRequest command, CancellationToken cancellationToken)
+ public Task SendBrowseCommand(BrowseRequest command, CancellationToken cancellationToken)
{
- var socket = GetSocket(session);
+ var socket = GetActiveSocket();
return socket.SendAsync(new WebSocketMessage<BrowseRequest>
{
@@ -77,9 +105,9 @@ namespace MediaBrowser.Server.Implementations.Session
}, cancellationToken);
}
- public Task SendPlaystateCommand(SessionInfo session, PlaystateRequest command, CancellationToken cancellationToken)
+ public Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken)
{
- var socket = GetSocket(session);
+ var socket = GetActiveSocket();
return socket.SendAsync(new WebSocketMessage<PlaystateRequest>
{
@@ -88,5 +116,34 @@ namespace MediaBrowser.Server.Implementations.Session
}, cancellationToken);
}
+
+ public Task SendLibraryUpdateInfo(LibraryUpdateInfo info, CancellationToken cancellationToken)
+ {
+ var socket = GetActiveSocket();
+
+ return socket.SendAsync(new WebSocketMessage<LibraryUpdateInfo>
+ {
+ MessageType = "Playstate",
+ Data = info
+
+ }, cancellationToken);
+ }
+
+ /// <summary>
+ /// Sends the restart required message.
+ /// </summary>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>Task.</returns>
+ public Task SendRestartRequiredMessage(CancellationToken cancellationToken)
+ {
+ var socket = GetActiveSocket();
+
+ return socket.SendAsync(new WebSocketMessage<SystemInfo>
+ {
+ MessageType = "RestartRequired",
+ Data = _appHost.GetSystemInfo()
+
+ }, cancellationToken);
+ }
}
}