From 501dedb13cd59dc2683ac4192cd11289bd304cfb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 24 Mar 2014 08:47:39 -0400 Subject: [PATCH] stub out dlna server --- .../ScheduledTasksWebSocketListener.cs | 22 +- .../Net/BasePeriodicWebSocketListener.cs | 18 +- MediaBrowser.Dlna/MediaBrowser.Dlna.csproj | 9 +- .../Server/DlnaServerEntryPoint.cs | 115 ++++++++ MediaBrowser.Dlna/Server/Headers.cs | 164 +++++++++++ MediaBrowser.Dlna/Server/RawHeaders.cs | 16 ++ MediaBrowser.Dlna/Server/SsdpHandler.cs | 260 ++++++++++++++++++ MediaBrowser.Dlna/Server/UpnpDevice.cs | 28 ++ .../Configuration/DlnaOptions.cs | 2 + 9 files changed, 623 insertions(+), 11 deletions(-) create mode 100644 MediaBrowser.Dlna/Server/DlnaServerEntryPoint.cs create mode 100644 MediaBrowser.Dlna/Server/Headers.cs create mode 100644 MediaBrowser.Dlna/Server/RawHeaders.cs create mode 100644 MediaBrowser.Dlna/Server/SsdpHandler.cs create mode 100644 MediaBrowser.Dlna/Server/UpnpDevice.cs diff --git a/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs b/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs index c143635bf..0d3f5dfcd 100644 --- a/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs +++ b/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs @@ -39,6 +39,8 @@ namespace MediaBrowser.Api.ScheduledTasks TaskManager = taskManager; } + private bool _lastResponseHadTasksRunning = true; + /// /// Gets the data to send. /// @@ -46,7 +48,25 @@ namespace MediaBrowser.Api.ScheduledTasks /// Task{IEnumerable{TaskInfo}}. protected override Task> GetDataToSend(object state) { - return Task.FromResult(TaskManager.ScheduledTasks + var tasks = TaskManager.ScheduledTasks.ToList(); + + var anyRunning = tasks.Any(i => i.State != TaskState.Idle); + + if (anyRunning) + { + _lastResponseHadTasksRunning = true; + } + else + { + if (!_lastResponseHadTasksRunning) + { + return Task.FromResult>(null); + } + + _lastResponseHadTasksRunning = false; + } + + return Task.FromResult(tasks .OrderBy(i => i.Name) .Select(ScheduledTaskHelpers.GetTaskInfo) .Where(i => !i.IsHidden)); diff --git a/MediaBrowser.Common/Net/BasePeriodicWebSocketListener.cs b/MediaBrowser.Common/Net/BasePeriodicWebSocketListener.cs index 4ff34cfa1..33d3f368b 100644 --- a/MediaBrowser.Common/Net/BasePeriodicWebSocketListener.cs +++ b/MediaBrowser.Common/Net/BasePeriodicWebSocketListener.cs @@ -1,11 +1,11 @@ -using System.Globalization; -using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Net; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Model.Net; namespace MediaBrowser.Common.Net { @@ -16,6 +16,7 @@ namespace MediaBrowser.Common.Net /// The type of the T state type. public abstract class BasePeriodicWebSocketListener : IWebSocketListener, IDisposable where TStateType : class, new() + where TReturnDataType : class { /// /// The _active connections @@ -144,12 +145,15 @@ namespace MediaBrowser.Common.Net var data = await GetDataToSend(tuple.Item4).ConfigureAwait(false); - await connection.SendAsync(new WebSocketMessage + if (data != null) { - MessageType = Name, - Data = data + await connection.SendAsync(new WebSocketMessage + { + MessageType = Name, + Data = data - }, tuple.Item2.Token).ConfigureAwait(false); + }, tuple.Item2.Token).ConfigureAwait(false); + } tuple.Item5.Release(); } diff --git a/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj b/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj index 4eb305e0f..bea281b61 100644 --- a/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj +++ b/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj @@ -98,6 +98,11 @@ + + + + + @@ -113,9 +118,7 @@ MediaBrowser.Model - - - +