Auto discover published URL override
This commit is contained in:
parent
62e251663f
commit
b737301c70
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||||
using Emby.Server.Implementations.Udp;
|
using Emby.Server.Implementations.Udp;
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Controller.Plugins;
|
using MediaBrowser.Controller.Plugins;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Emby.Server.Implementations.EntryPoints
|
namespace Emby.Server.Implementations.EntryPoints
|
||||||
|
@ -22,6 +23,7 @@ namespace Emby.Server.Implementations.EntryPoints
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
|
private readonly IConfiguration _config;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The UDP server.
|
/// The UDP server.
|
||||||
|
@ -35,18 +37,19 @@ namespace Emby.Server.Implementations.EntryPoints
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public UdpServerEntryPoint(
|
public UdpServerEntryPoint(
|
||||||
ILogger<UdpServerEntryPoint> logger,
|
ILogger<UdpServerEntryPoint> logger,
|
||||||
IServerApplicationHost appHost)
|
IServerApplicationHost appHost,
|
||||||
|
IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
|
_config = configuration;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task RunAsync()
|
public async Task RunAsync()
|
||||||
{
|
{
|
||||||
_udpServer = new UdpServer(_logger, _appHost);
|
_udpServer = new UdpServer(_logger, _appHost, _config);
|
||||||
_udpServer.Start(PortNumber, _cancellationTokenSource.Token);
|
_udpServer.Start(PortNumber, _cancellationTokenSource.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,5 +36,10 @@ namespace Emby.Server.Implementations
|
||||||
/// Gets the value of the --plugin-manifest-url command line option.
|
/// Gets the value of the --plugin-manifest-url command line option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string PluginManifestUrl { get; }
|
string PluginManifestUrl { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the value of the --auto-discover-publish-url command line option.
|
||||||
|
/// </summary>
|
||||||
|
string AutoDiscoverPublishUrl { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.ApiClient;
|
using MediaBrowser.Model.ApiClient;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Emby.Server.Implementations.Udp
|
namespace Emby.Server.Implementations.Udp
|
||||||
|
@ -21,6 +22,12 @@ namespace Emby.Server.Implementations.Udp
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
|
private readonly IConfiguration _config;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Address Override Configuration Key
|
||||||
|
/// </summary>
|
||||||
|
public const string AddressOverrideConfigKey = "AutoDiscoverAddressOverride";
|
||||||
|
|
||||||
private Socket _udpSocket;
|
private Socket _udpSocket;
|
||||||
private IPEndPoint _endpoint;
|
private IPEndPoint _endpoint;
|
||||||
|
@ -31,15 +38,26 @@ namespace Emby.Server.Implementations.Udp
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="UdpServer" /> class.
|
/// Initializes a new instance of the <see cref="UdpServer" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public UdpServer(ILogger logger, IServerApplicationHost appHost)
|
public UdpServer(ILogger logger, IServerApplicationHost appHost, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
|
_config = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RespondToV2Message(string messageText, EndPoint endpoint, CancellationToken cancellationToken)
|
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))
|
if (!string.IsNullOrEmpty(localUrl))
|
||||||
{
|
{
|
||||||
|
@ -105,7 +123,7 @@ namespace Emby.Server.Implementations.Udp
|
||||||
}
|
}
|
||||||
catch (SocketException ex)
|
catch (SocketException ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Failed to receive data drom socket");
|
_logger.LogError(ex, "Failed to receive data from socket");
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using CommandLine;
|
using CommandLine;
|
||||||
using Emby.Server.Implementations;
|
using Emby.Server.Implementations;
|
||||||
|
using Emby.Server.Implementations.EntryPoints;
|
||||||
|
using Emby.Server.Implementations.Udp;
|
||||||
using Emby.Server.Implementations.Updates;
|
using Emby.Server.Implementations.Updates;
|
||||||
using MediaBrowser.Controller.Extensions;
|
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")]
|
[Option("plugin-manifest-url", Required = false, HelpText = "A custom URL for the plugin repository JSON manifest")]
|
||||||
public string? PluginManifestUrl { get; set; }
|
public string? PluginManifestUrl { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
[Option("auto-discover-publish-url", Required = false, HelpText = "Jellyfin Server URL to publish via auto discover process")]
|
||||||
|
public string? AutoDiscoverPublishUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the command line options as a dictionary that can be used in the .NET configuration system.
|
/// Gets the command line options as a dictionary that can be used in the .NET configuration system.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -98,6 +104,11 @@ namespace Jellyfin.Server
|
||||||
config.Add(ConfigurationExtensions.HostWebClientKey, bool.FalseString);
|
config.Add(ConfigurationExtensions.HostWebClientKey, bool.FalseString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (AutoDiscoverPublishUrl != null)
|
||||||
|
{
|
||||||
|
config.Add(UdpServer.AddressOverrideConfigKey, AutoDiscoverPublishUrl);
|
||||||
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user