From 13563b604756152fe2f6630a4cb8fd2994e5bb62 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 25 Feb 2014 23:38:21 -0500 Subject: [PATCH] Add upnp configuration --- MediaBrowser.Api/UserService.cs | 22 ++- .../HttpClientManager/HttpClientManager.cs | 12 +- MediaBrowser.Common/Net/HttpRequestOptions.cs | 12 +- MediaBrowser.Controller/Entities/Folder.cs | 51 +---- MediaBrowser.Dlna/MediaBrowser.Dlna.csproj | 55 ++++++ MediaBrowser.Dlna/Properties/AssemblyInfo.cs | 31 ++++ .../Configuration/ServerConfiguration.cs | 8 + MediaBrowser.Mono.sln | 10 + .../Manager/ProviderManager.cs | 4 + .../TV/MissingEpisodeProvider.cs | 17 +- .../EntryPoints/ExternalPortForwarding.cs | 174 ++++++++++++++++++ .../FileOrganization/TvFolderOrganizer.cs | 2 +- .../IO/LibraryMonitor.cs | 11 +- ...MediaBrowser.Server.Implementations.csproj | 4 + .../ServerManager/ServerManager.cs | 2 - .../WebSocket/FleckServer.cs | 54 ------ .../WebSocket/FleckWebSocket.cs | 47 ----- .../packages.config | 1 + .../MediaBrowser.Server.Mono.csproj | 4 + .../MediaBrowser.ServerApplication.csproj | 4 + MediaBrowser.sln | 16 ++ 21 files changed, 383 insertions(+), 158 deletions(-) create mode 100644 MediaBrowser.Dlna/MediaBrowser.Dlna.csproj create mode 100644 MediaBrowser.Dlna/Properties/AssemblyInfo.cs create mode 100644 MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs delete mode 100644 MediaBrowser.Server.Implementations/WebSocket/FleckServer.cs delete mode 100644 MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs index 8e94d2c83a..18c3bd0962 100644 --- a/MediaBrowser.Api/UserService.cs +++ b/MediaBrowser.Api/UserService.cs @@ -189,7 +189,7 @@ namespace MediaBrowser.Api { throw new ArgumentNullException("xmlSerializer"); } - + _xmlSerializer = xmlSerializer; _userManager = userManager; _dtoService = dtoService; @@ -306,6 +306,26 @@ namespace MediaBrowser.Api var auth = AuthorizationRequestFilterAttribute.GetAuthorization(Request); + // Login in the old way if the header is missing + if (string.IsNullOrEmpty(auth.Client) || + string.IsNullOrEmpty(auth.Device) || + string.IsNullOrEmpty(auth.DeviceId) || + string.IsNullOrEmpty(auth.Version)) + { + var success = await _userManager.AuthenticateUser(user, request.Password).ConfigureAwait(false); + + if (!success) + { + // Unauthorized + throw new UnauthorizedAccessException("Invalid user or password entered."); + } + + return new AuthenticationResult + { + User = _dtoService.GetUserDto(user) + }; + } + var session = await _sessionMananger.AuthenticateNewSession(user, request.Password, auth.Client, auth.Version, auth.DeviceId, auth.Device, Request.RemoteIp).ConfigureAwait(false); diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 2e0035f5d5..8e5cab43c1 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -114,7 +114,11 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager } request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None; - request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate); + + request.CachePolicy = options.CachePolicy == Net.HttpRequestCachePolicy.None ? + new RequestCachePolicy(RequestCacheLevel.BypassCache) : + new RequestCachePolicy(RequestCacheLevel.Revalidate); + request.ConnectionGroupName = GetHostFromUrl(options.Url); request.KeepAlive = true; request.Method = method; @@ -144,7 +148,11 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager } request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None; - request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate); + + request.CachePolicy = options.CachePolicy == Net.HttpRequestCachePolicy.None ? + new RequestCachePolicy(RequestCacheLevel.BypassCache) : + new RequestCachePolicy(RequestCacheLevel.Revalidate); + request.ConnectionGroupName = GetHostFromUrl(options.Url); request.KeepAlive = true; request.Method = method; diff --git a/MediaBrowser.Common/Net/HttpRequestOptions.cs b/MediaBrowser.Common/Net/HttpRequestOptions.cs index ebe76e62c7..659d230cff 100644 --- a/MediaBrowser.Common/Net/HttpRequestOptions.cs +++ b/MediaBrowser.Common/Net/HttpRequestOptions.cs @@ -71,7 +71,9 @@ namespace MediaBrowser.Common.Net public string RequestContent { get; set; } public bool BufferContent { get; set; } - + + public HttpRequestCachePolicy CachePolicy { get; set; } + private string GetHeaderValue(string name) { string value; @@ -89,7 +91,15 @@ namespace MediaBrowser.Common.Net EnableHttpCompression = true; BufferContent = true; + CachePolicy = HttpRequestCachePolicy.None; + RequestHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); } } + + public enum HttpRequestCachePolicy + { + None = 1, + Validate = 2 + } } diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 954b36bf24..7ae2304c4b 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -305,12 +305,6 @@ namespace MediaBrowser.Controller.Entities return GetCachedChildren(); } - /// - /// Gets or sets the current validation cancellation token source. - /// - /// The current validation cancellation token source. - private CancellationTokenSource CurrentValidationCancellationTokenSource { get; set; } - public Task ValidateChildren(IProgress progress, CancellationToken cancellationToken) { return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions()); @@ -331,48 +325,9 @@ namespace MediaBrowser.Controller.Entities return ValidateChildrenWithCancellationSupport(progress, cancellationToken, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService); } - private async Task ValidateChildrenWithCancellationSupport(IProgress progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) + private Task ValidateChildrenWithCancellationSupport(IProgress progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) { - cancellationToken.ThrowIfCancellationRequested(); - - // Cancel the current validation, if any - if (CurrentValidationCancellationTokenSource != null) - { - CurrentValidationCancellationTokenSource.Cancel(); - } - - // Create an inner cancellation token. This can cancel all validations from this level on down, - // but nothing above this - var innerCancellationTokenSource = new CancellationTokenSource(); - - try - { - CurrentValidationCancellationTokenSource = innerCancellationTokenSource; - - var linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(innerCancellationTokenSource.Token, cancellationToken); - - await ValidateChildrenInternal(progress, linkedCancellationTokenSource.Token, recursive, refreshChildMetadata, refreshOptions, directoryService).ConfigureAwait(false); - } - catch (OperationCanceledException ex) - { - Logger.Info("ValidateChildren cancelled for " + Name); - - // If the outer cancelletion token in the cause for the cancellation, throw it - if (cancellationToken.IsCancellationRequested && ex.CancellationToken == cancellationToken) - { - throw; - } - } - finally - { - // Null out the token source - if (CurrentValidationCancellationTokenSource == innerCancellationTokenSource) - { - CurrentValidationCancellationTokenSource = null; - } - - innerCancellationTokenSource.Dispose(); - } + return ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService); } private Dictionary GetActualChildrenDictionary() @@ -384,7 +339,7 @@ namespace MediaBrowser.Controller.Entities var id = child.Id; if (dictionary.ContainsKey(id)) { - Logger.Error( "Found folder containing items with duplicate id. Path: {0}, Child Name: {1}", + Logger.Error("Found folder containing items with duplicate id. Path: {0}, Child Name: {1}", Path ?? Name, child.Path ?? child.Name); } diff --git a/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj b/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj new file mode 100644 index 0000000000..c3ba97e9be --- /dev/null +++ b/MediaBrowser.Dlna/MediaBrowser.Dlna.csproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C} + Library + Properties + MediaBrowser.Dlna + MediaBrowser.Dlna + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + Properties\SharedVersion.cs + + + + + + \ No newline at end of file diff --git a/MediaBrowser.Dlna/Properties/AssemblyInfo.cs b/MediaBrowser.Dlna/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..1d9f7cd971 --- /dev/null +++ b/MediaBrowser.Dlna/Properties/AssemblyInfo.cs @@ -0,0 +1,31 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MediaBrowser.Dlna")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MediaBrowser.Dlna")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c319ebfa-fd9d-42e4-ae74-a40039a6a688")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// \ No newline at end of file diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 21414768e0..1b4a6813ec 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -27,6 +27,12 @@ namespace MediaBrowser.Model.Configuration /// true if [enable HTTP level logging]; otherwise, false. public bool EnableHttpLevelLogging { get; set; } + /// + /// Gets or sets a value indicating whether [enable u pn p]. + /// + /// true if [enable u pn p]; otherwise, false. + public bool EnableUPnP { get; set; } + /// /// Gets or sets the HTTP server port number. /// @@ -222,6 +228,8 @@ namespace MediaBrowser.Model.Configuration EnableAutomaticRestart = true; EnablePeoplePrefixSubFolders = true; + EnableUPnP = true; + MinResumePct = 5; MaxResumePct = 90; MinResumeDurationSeconds = Convert.ToInt32(TimeSpan.FromMinutes(5).TotalSeconds); diff --git a/MediaBrowser.Mono.sln b/MediaBrowser.Mono.sln index c951fda721..4f6ce7a584 100644 --- a/MediaBrowser.Mono.sln +++ b/MediaBrowser.Mono.sln @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Api", "MediaBr EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Server.Mono", "MediaBrowser.Server.Mono\MediaBrowser.Server.Mono.csproj", "{175A9388-F352-4586-A6B4-070DED62B644}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Dlna", "MediaBrowser.Dlna\MediaBrowser.Dlna.csproj", "{734098EB-6DC1-4DD0-A1CA-3140DCD2737C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -99,6 +101,14 @@ Global {C4D2573A-3FD3-441F-81AF-174AC4CD4E1D}.Release|Any CPU.Build.0 = Release|Any CPU {C4D2573A-3FD3-441F-81AF-174AC4CD4E1D}.Release|x86.ActiveCfg = Release|Any CPU {C4D2573A-3FD3-441F-81AF-174AC4CD4E1D}.Release|x86.Build.0 = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Debug|x86.ActiveCfg = Debug|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Debug|x86.Build.0 = Debug|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release Mono|Any CPU.ActiveCfg = Release Mono|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release Mono|Any CPU.Build.0 = Release Mono|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|Any CPU.Build.0 = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|x86.ActiveCfg = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution StartupItem = MediaBrowser.Server.Mono\MediaBrowser.Server.Mono.csproj diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index c8989529b8..83331ebbb5 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -182,6 +182,10 @@ namespace MediaBrowser.Providers.Manager return result; } + catch (OperationCanceledException) + { + return new List(); + } catch (Exception ex) { _logger.ErrorException("{0} failed in GetImageInfos for type {1}", ex, provider.GetType().Name, item.GetType().Name); diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index f4191fe8f4..c620a6c334 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -36,7 +36,22 @@ namespace MediaBrowser.Providers.TV { foreach (var seriesGroup in series) { - await Run(seriesGroup, cancellationToken).ConfigureAwait(false); + try + { + await Run(seriesGroup, cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + break; + } + catch (DirectoryNotFoundException) + { + _logger.Warn("Series files missing for series id {0}", seriesGroup.Key); + } + catch (Exception ex) + { + _logger.ErrorException("Error in missing episode provider for series id {0}", ex, seriesGroup.Key); + } } } diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs new file mode 100644 index 0000000000..43037d6ce0 --- /dev/null +++ b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -0,0 +1,174 @@ +using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Plugins; +using MediaBrowser.Model.Logging; +using Mono.Nat; +using System; +using System.IO; +using System.Text; + +namespace MediaBrowser.Server.Implementations.EntryPoints +{ + public class ExternalPortForwarding : IServerEntryPoint + { + private readonly IServerApplicationHost _appHost; + private readonly ILogger _logger; + private readonly IServerConfigurationManager _config; + + private bool _isStarted; + + public ExternalPortForwarding(ILogger logger, IServerApplicationHost appHost, IServerConfigurationManager config) + { + _logger = logger; + _appHost = appHost; + _config = config; + + _config.ConfigurationUpdated += _config_ConfigurationUpdated; + } + + void _config_ConfigurationUpdated(object sender, EventArgs e) + { + var enable = _config.Configuration.EnableUPnP; + + if (enable && !_isStarted) + { + Reload(); + } + else if (!enable && _isStarted) + { + DisposeNat(); + } + } + + public void Run() + { + NatUtility.Logger = new LogWriter(_logger); + + Reload(); + } + + private void Reload() + { + if (_config.Configuration.EnableUPnP) + { + _logger.Debug("Starting NAT discovery"); + + NatUtility.DeviceFound += NatUtility_DeviceFound; + NatUtility.DeviceLost += NatUtility_DeviceLost; + NatUtility.UnhandledException += NatUtility_UnhandledException; + NatUtility.StartDiscovery(); + + _isStarted = true; + } + } + + void NatUtility_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + var ex = e.ExceptionObject as Exception; + + if (ex == null) + { + _logger.Error("Unidentified error reported by Mono.Nat"); + } + else + { + // Seeing some blank exceptions coming through here + _logger.ErrorException("Error reported by Mono.Nat: ", ex); + } + } + + void NatUtility_DeviceFound(object sender, DeviceEventArgs e) + { + try + { + var device = e.Device; + _logger.Debug("NAT device found: {0}", device.LocalAddress.ToString()); + + CreateRules(device); + } + catch (Exception ex) + { + _logger.ErrorException("Error creating port forwarding rules", ex); + } + } + + private void CreateRules(INatDevice device) + { + var info = _appHost.GetSystemInfo(); + + CreatePortMap(device, info.HttpServerPortNumber); + + if (info.WebSocketPortNumber != info.HttpServerPortNumber) + { + CreatePortMap(device, info.WebSocketPortNumber); + } + } + + private void CreatePortMap(INatDevice device, int port) + { + _logger.Info("Creating port map on port {0}", port); + + device.CreatePortMap(new Mapping(Protocol.Tcp, port, port) + { + Description = "Media Browser Server" + }); + } + + void NatUtility_DeviceLost(object sender, DeviceEventArgs e) + { + var device = e.Device; + _logger.Debug("NAT device lost: {0}", device.LocalAddress.ToString()); + } + + public void Dispose() + { + DisposeNat(); + } + + private void DisposeNat() + { + _logger.Debug("Stopping NAT discovery"); + + try + { + NatUtility.DeviceFound -= NatUtility_DeviceFound; + NatUtility.DeviceLost -= NatUtility_DeviceLost; + NatUtility.UnhandledException -= NatUtility_UnhandledException; + NatUtility.StopDiscovery(); + } + catch (Exception ex) + { + _logger.ErrorException("Error stopping NAT Discovery", ex); + } + finally + { + _isStarted = false; + } + } + + private class LogWriter : TextWriter + { + private readonly ILogger _logger; + + public LogWriter(ILogger logger) + { + _logger = logger; + } + + public override Encoding Encoding + { + get { return Encoding.UTF8; } + } + + public override void WriteLine(string format, params object[] arg) + { + _logger.Debug(format, arg); + } + + public override void WriteLine(string value) + { + _logger.Debug(value); + } + } + } +} diff --git a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs index 9df6e7f1c9..7edcf9739c 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs @@ -170,7 +170,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization { File.Delete(file.FullName); } - catch (IOException ex) + catch (Exception ex) { _logger.ErrorException("Error deleting file {0}", ex, file.FullName); } diff --git a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs index fa1d4b0d51..cbc4a8c244 100644 --- a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs +++ b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs @@ -39,7 +39,16 @@ namespace MediaBrowser.Server.Implementations.IO /// /// Any file name ending in any of these will be ignored by the watchers /// - private readonly IReadOnlyList _alwaysIgnoreFiles = new List { "thumbs.db", "small.jpg", "albumart.jpg" }; + private readonly IReadOnlyList _alwaysIgnoreFiles = new List + { + "thumbs.db", + "small.jpg", + "albumart.jpg", + + // WMC temp recording directories that will constantly be written to + "TempRec", + "TempSBE" + }; /// /// The timer lock diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index c8e7903d1b..d83f010529 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -56,6 +56,9 @@ False ..\packages\MediaBrowser.BdInfo.1.0.0.10\lib\net35\DvdLib.dll + + ..\packages\Mono.Nat.1.1.13\lib\Net40\Mono.Nat.dll + ..\ThirdParty\ServiceStack\ServiceStack.Api.Swagger.dll @@ -112,6 +115,7 @@ + diff --git a/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs b/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs index fecd72a395..e66b87b0c8 100644 --- a/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs +++ b/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs @@ -154,8 +154,6 @@ namespace MediaBrowser.Server.Implementations.ServerManager /// private void ReloadHttpServer(IEnumerable urlPrefixes, bool enableHttpLogging) { - DisposeHttpServer(); - _logger.Info("Loading Http Server"); try diff --git a/MediaBrowser.Server.Implementations/WebSocket/FleckServer.cs b/MediaBrowser.Server.Implementations/WebSocket/FleckServer.cs deleted file mode 100644 index 2c47a366e0..0000000000 --- a/MediaBrowser.Server.Implementations/WebSocket/FleckServer.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Fleck; -using MediaBrowser.Common.Net; -using System; -using IWebSocketServer = MediaBrowser.Common.Net.IWebSocketServer; - -namespace MediaBrowser.Server.Implementations.WebSocket -{ - public class FleckServer : IWebSocketServer - { - private WebSocketServer _server; - - public void Start(int portNumber) - { - var server = new WebSocketServer("ws://localhost:" + portNumber); - - server.Start(socket => - { - socket.OnOpen = () => OnClientConnected(socket); - }); - - _server = server; - } - - public void Stop() - { - _server.Dispose(); - } - - private void OnClientConnected(Fleck.IWebSocketConnection context) - { - if (WebSocketConnected != null) - { - var socket = new FleckWebSocket(context); - - WebSocketConnected(this, new WebSocketConnectEventArgs - { - WebSocket = socket, - Endpoint = context.ConnectionInfo.ClientIpAddress + ":" + context.ConnectionInfo.ClientPort - }); - } - } - public event EventHandler WebSocketConnected; - - public int Port - { - get { return _server.Port; } - } - - public void Dispose() - { - _server.Dispose(); - } - } -} diff --git a/MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs b/MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs deleted file mode 100644 index 3667fab070..0000000000 --- a/MediaBrowser.Server.Implementations/WebSocket/FleckWebSocket.cs +++ /dev/null @@ -1,47 +0,0 @@ -using MediaBrowser.Common.Net; -using MediaBrowser.Model.Net; -using System; -using System.Threading; -using System.Threading.Tasks; -using IWebSocketConnection = Fleck.IWebSocketConnection; - -namespace MediaBrowser.Server.Implementations.WebSocket -{ - public class FleckWebSocket : IWebSocket - { - private readonly IWebSocketConnection _connection; - - public FleckWebSocket(IWebSocketConnection connection) - { - _connection = connection; - - _connection.OnMessage = OnReceiveData; - } - - public WebSocketState State - { - get { return _connection.IsAvailable ? WebSocketState.Open : WebSocketState.Closed; } - } - - private void OnReceiveData(string data) - { - if (OnReceive != null) - { - OnReceive(data); - } - } - - public Task SendAsync(byte[] bytes, WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken) - { - return Task.Run(() => _connection.Send(bytes)); - } - - public void Dispose() - { - _connection.Close(); - } - - public Action OnReceiveBytes { get; set; } - public Action OnReceive { get; set; } - } -} diff --git a/MediaBrowser.Server.Implementations/packages.config b/MediaBrowser.Server.Implementations/packages.config index 4b96e57f79..258e0639d3 100644 --- a/MediaBrowser.Server.Implementations/packages.config +++ b/MediaBrowser.Server.Implementations/packages.config @@ -2,6 +2,7 @@ + \ No newline at end of file diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj index 6b000435ab..c8453e7716 100644 --- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj +++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj @@ -100,6 +100,10 @@ {442B5058-DCAF-4263-BB6A-F21E31120A1B} MediaBrowser.Providers + + {734098eb-6dc1-4dd0-a1ca-3140dcd2737c} + MediaBrowser.Dlna + {7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B} MediaBrowser.Model diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index b588997402..c3eb4fd6ab 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -191,6 +191,10 @@ {17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2} MediaBrowser.Controller + + {734098eb-6dc1-4dd0-a1ca-3140dcd2737c} + MediaBrowser.Dlna + {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} MediaBrowser.Model diff --git a/MediaBrowser.sln b/MediaBrowser.sln index a3e35f6038..7ac1580659 100644 --- a/MediaBrowser.sln +++ b/MediaBrowser.sln @@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Model.Portable EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.ServerApplication", "MediaBrowser.ServerApplication\MediaBrowser.ServerApplication.csproj", "{94ADE4D3-B7EC-45CD-A200-CC469433072B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Dlna", "MediaBrowser.Dlna\MediaBrowser.Dlna.csproj", "{734098EB-6DC1-4DD0-A1CA-3140DCD2737C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -231,6 +233,20 @@ Global {94ADE4D3-B7EC-45CD-A200-CC469433072B}.Release|Win32.ActiveCfg = Release|Any CPU {94ADE4D3-B7EC-45CD-A200-CC469433072B}.Release|x64.ActiveCfg = Release|Any CPU {94ADE4D3-B7EC-45CD-A200-CC469433072B}.Release|x86.ActiveCfg = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Debug|Win32.ActiveCfg = Debug|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Debug|x64.ActiveCfg = Debug|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Debug|x86.ActiveCfg = Debug|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|Any CPU.Build.0 = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|Win32.ActiveCfg = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|x64.ActiveCfg = Release|Any CPU + {734098EB-6DC1-4DD0-A1CA-3140DCD2737C}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE