From b737301c709ba4c2575b2a38ddbba6de96477413 Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Sat, 2 May 2020 17:56:09 +0100 Subject: [PATCH 1/4] Auto discover published URL override --- .../EntryPoints/UdpServerEntryPoint.cs | 9 ++++--- .../IStartupOptions.cs | 5 ++++ Emby.Server.Implementations/Udp/UdpServer.cs | 24 ++++++++++++++++--- Jellyfin.Server/StartupOptions.cs | 11 +++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs index 50ba0f8fac..6929c81f92 100644 --- a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Emby.Server.Implementations.Udp; using MediaBrowser.Controller; using MediaBrowser.Controller.Plugins; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.EntryPoints @@ -22,6 +23,7 @@ namespace Emby.Server.Implementations.EntryPoints /// private readonly ILogger _logger; private readonly IServerApplicationHost _appHost; + private readonly IConfiguration _config; /// /// The UDP server. @@ -35,18 +37,19 @@ namespace Emby.Server.Implementations.EntryPoints /// public UdpServerEntryPoint( ILogger logger, - IServerApplicationHost appHost) + IServerApplicationHost appHost, + IConfiguration configuration) { _logger = logger; _appHost = appHost; - + _config = configuration; } /// public async Task RunAsync() { - _udpServer = new UdpServer(_logger, _appHost); + _udpServer = new UdpServer(_logger, _appHost, _config); _udpServer.Start(PortNumber, _cancellationTokenSource.Token); } diff --git a/Emby.Server.Implementations/IStartupOptions.cs b/Emby.Server.Implementations/IStartupOptions.cs index 16b68170be..a3a047057d 100644 --- a/Emby.Server.Implementations/IStartupOptions.cs +++ b/Emby.Server.Implementations/IStartupOptions.cs @@ -36,5 +36,10 @@ namespace Emby.Server.Implementations /// Gets the value of the --plugin-manifest-url command line option. /// string PluginManifestUrl { get; } + + /// + /// Gets the value of the --auto-discover-publish-url command line option. + /// + string AutoDiscoverPublishUrl { get; } } } diff --git a/Emby.Server.Implementations/Udp/UdpServer.cs b/Emby.Server.Implementations/Udp/UdpServer.cs index c91d137a72..57228d208d 100644 --- a/Emby.Server.Implementations/Udp/UdpServer.cs +++ b/Emby.Server.Implementations/Udp/UdpServer.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using MediaBrowser.Controller; using MediaBrowser.Model.ApiClient; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Udp @@ -21,6 +22,12 @@ namespace Emby.Server.Implementations.Udp /// private readonly ILogger _logger; private readonly IServerApplicationHost _appHost; + private readonly IConfiguration _config; + + /// + /// Address Override Configuration Key + /// + public const string AddressOverrideConfigKey = "AutoDiscoverAddressOverride"; private Socket _udpSocket; private IPEndPoint _endpoint; @@ -31,15 +38,26 @@ namespace Emby.Server.Implementations.Udp /// /// Initializes a new instance of the class. /// - public UdpServer(ILogger logger, IServerApplicationHost appHost) + public UdpServer(ILogger logger, IServerApplicationHost appHost, IConfiguration configuration) { _logger = logger; _appHost = appHost; + _config = configuration; } private async Task RespondToV2Message(string messageText, EndPoint endpoint, CancellationToken cancellationToken) { - var localUrl = await _appHost.GetLocalApiUrl(cancellationToken).ConfigureAwait(false); + string localUrl; + + if (!string.IsNullOrEmpty(_config[AddressOverrideConfigKey])) + { + localUrl = _config[AddressOverrideConfigKey]; + } + else + { + localUrl = await _appHost.GetLocalApiUrl(cancellationToken).ConfigureAwait(false); + } + if (!string.IsNullOrEmpty(localUrl)) { @@ -105,7 +123,7 @@ namespace Emby.Server.Implementations.Udp } catch (SocketException ex) { - _logger.LogError(ex, "Failed to receive data drom socket"); + _logger.LogError(ex, "Failed to receive data from socket"); } catch (OperationCanceledException) { diff --git a/Jellyfin.Server/StartupOptions.cs b/Jellyfin.Server/StartupOptions.cs index 6e15d058fc..135ba9d7f8 100644 --- a/Jellyfin.Server/StartupOptions.cs +++ b/Jellyfin.Server/StartupOptions.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using CommandLine; using Emby.Server.Implementations; +using Emby.Server.Implementations.EntryPoints; +using Emby.Server.Implementations.Udp; using Emby.Server.Implementations.Updates; using MediaBrowser.Controller.Extensions; @@ -80,6 +82,10 @@ namespace Jellyfin.Server [Option("plugin-manifest-url", Required = false, HelpText = "A custom URL for the plugin repository JSON manifest")] public string? PluginManifestUrl { get; set; } + /// + [Option("auto-discover-publish-url", Required = false, HelpText = "Jellyfin Server URL to publish via auto discover process")] + public string? AutoDiscoverPublishUrl { get; set; } + /// /// Gets the command line options as a dictionary that can be used in the .NET configuration system. /// @@ -98,6 +104,11 @@ namespace Jellyfin.Server config.Add(ConfigurationExtensions.HostWebClientKey, bool.FalseString); } + if (AutoDiscoverPublishUrl != null) + { + config.Add(UdpServer.AddressOverrideConfigKey, AutoDiscoverPublishUrl); + } + return config; } } From d7b2c2a17626e75ebb202fc9fa1186a88f670eec Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Wed, 20 May 2020 09:05:51 +0100 Subject: [PATCH 2/4] Renaming variable and refactoring IF statement --- Emby.Server.Implementations/IStartupOptions.cs | 4 +++- Emby.Server.Implementations/Udp/UdpServer.cs | 16 ++++------------ Jellyfin.Server/StartupOptions.cs | 9 +++++---- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Emby.Server.Implementations/IStartupOptions.cs b/Emby.Server.Implementations/IStartupOptions.cs index a3a047057d..5d22bfddc9 100644 --- a/Emby.Server.Implementations/IStartupOptions.cs +++ b/Emby.Server.Implementations/IStartupOptions.cs @@ -1,3 +1,5 @@ +using System; + namespace Emby.Server.Implementations { public interface IStartupOptions @@ -40,6 +42,6 @@ namespace Emby.Server.Implementations /// /// Gets the value of the --auto-discover-publish-url command line option. /// - string AutoDiscoverPublishUrl { get; } + Uri PublishedServerUrl { get; } } } diff --git a/Emby.Server.Implementations/Udp/UdpServer.cs b/Emby.Server.Implementations/Udp/UdpServer.cs index 57228d208d..1ae3888dc4 100644 --- a/Emby.Server.Implementations/Udp/UdpServer.cs +++ b/Emby.Server.Implementations/Udp/UdpServer.cs @@ -27,7 +27,7 @@ namespace Emby.Server.Implementations.Udp /// /// Address Override Configuration Key /// - public const string AddressOverrideConfigKey = "AutoDiscoverAddressOverride"; + public const string AddressOverrideConfigKey = "PublishedServerUrl"; private Socket _udpSocket; private IPEndPoint _endpoint; @@ -47,17 +47,9 @@ namespace Emby.Server.Implementations.Udp private async Task RespondToV2Message(string messageText, EndPoint endpoint, CancellationToken cancellationToken) { - string localUrl; - - if (!string.IsNullOrEmpty(_config[AddressOverrideConfigKey])) - { - localUrl = _config[AddressOverrideConfigKey]; - } - else - { - localUrl = await _appHost.GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - } - + string localUrl = !string.IsNullOrEmpty(_config[AddressOverrideConfigKey]) + ? _config[AddressOverrideConfigKey] + : await _appHost.GetLocalApiUrl(cancellationToken).ConfigureAwait(false); if (!string.IsNullOrEmpty(localUrl)) { diff --git a/Jellyfin.Server/StartupOptions.cs b/Jellyfin.Server/StartupOptions.cs index 135ba9d7f8..cc250b06e2 100644 --- a/Jellyfin.Server/StartupOptions.cs +++ b/Jellyfin.Server/StartupOptions.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using CommandLine; using Emby.Server.Implementations; @@ -83,8 +84,8 @@ namespace Jellyfin.Server public string? PluginManifestUrl { get; set; } /// - [Option("auto-discover-publish-url", Required = false, HelpText = "Jellyfin Server URL to publish via auto discover process")] - public string? AutoDiscoverPublishUrl { get; set; } + [Option("published-server-url", Required = false, HelpText = "Jellyfin Server URL to publish via auto discover process")] + public Uri? PublishedServerUrl { get; set; } /// /// Gets the command line options as a dictionary that can be used in the .NET configuration system. @@ -104,9 +105,9 @@ namespace Jellyfin.Server config.Add(ConfigurationExtensions.HostWebClientKey, bool.FalseString); } - if (AutoDiscoverPublishUrl != null) + if (PublishedServerUrl != null) { - config.Add(UdpServer.AddressOverrideConfigKey, AutoDiscoverPublishUrl); + config.Add(UdpServer.AddressOverrideConfigKey, PublishedServerUrl.ToString()); } return config; From a646a91e158de8f26cc24e6b87d4a665942c28d9 Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Wed, 20 May 2020 14:29:18 +0100 Subject: [PATCH 3/4] Update Emby.Server.Implementations/IStartupOptions.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/IStartupOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/IStartupOptions.cs b/Emby.Server.Implementations/IStartupOptions.cs index 5d22bfddc9..acae702f30 100644 --- a/Emby.Server.Implementations/IStartupOptions.cs +++ b/Emby.Server.Implementations/IStartupOptions.cs @@ -40,7 +40,7 @@ namespace Emby.Server.Implementations string PluginManifestUrl { get; } /// - /// Gets the value of the --auto-discover-publish-url command line option. + /// Gets the value of the --published-server-url command line option. /// Uri PublishedServerUrl { get; } } From 09915363c2d5f2febed41e803476c7ec6049a06e Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Sun, 24 May 2020 09:22:13 +0100 Subject: [PATCH 4/4] Update Emby.Server.Implementations/Udp/UdpServer.cs Co-authored-by: Mark Monteiro --- Emby.Server.Implementations/Udp/UdpServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Udp/UdpServer.cs b/Emby.Server.Implementations/Udp/UdpServer.cs index 1ae3888dc4..a26f714b12 100644 --- a/Emby.Server.Implementations/Udp/UdpServer.cs +++ b/Emby.Server.Implementations/Udp/UdpServer.cs @@ -25,7 +25,7 @@ namespace Emby.Server.Implementations.Udp private readonly IConfiguration _config; /// - /// Address Override Configuration Key + /// Address Override Configuration Key. /// public const string AddressOverrideConfigKey = "PublishedServerUrl";