From eb72c2db513f5306eecccb94f0f1cd5296a7d7db Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 2 Oct 2013 21:22:50 -0400 Subject: updated nuget --- .../Session/WebSocketController.cs | 85 ++++++++++++++++++---- 1 file changed, 71 insertions(+), 14 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Session/WebSocketController.cs') 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 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(); } - 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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 + { + MessageType = "Playstate", + Data = info + + }, cancellationToken); + } + + /// + /// Sends the restart required message. + /// + /// The cancellation token. + /// Task. + public Task SendRestartRequiredMessage(CancellationToken cancellationToken) + { + var socket = GetActiveSocket(); + + return socket.SendAsync(new WebSocketMessage + { + MessageType = "RestartRequired", + Data = _appHost.GetSystemInfo() + + }, cancellationToken); + } } } -- cgit v1.2.3