Use the new method in DLNA

This commit is contained in:
cvium 2021-11-08 10:58:04 +01:00
parent f03e77a4d5
commit 82e6a21f3b
3 changed files with 13 additions and 16 deletions

View File

@ -52,7 +52,6 @@ namespace Emby.Dlna.Main
private readonly ISocketFactory _socketFactory; private readonly ISocketFactory _socketFactory;
private readonly INetworkManager _networkManager; private readonly INetworkManager _networkManager;
private readonly object _syncLock = new object(); private readonly object _syncLock = new object();
private readonly NetworkConfiguration _netConfig;
private readonly bool _disabled; private readonly bool _disabled;
private PlayToManager _manager; private PlayToManager _manager;
@ -125,8 +124,8 @@ namespace Emby.Dlna.Main
config); config);
Current = this; Current = this;
_netConfig = config.GetConfiguration<NetworkConfiguration>("network"); var netConfig = config.GetConfiguration<NetworkConfiguration>("network");
_disabled = appHost.ListenWithHttps && _netConfig.RequireHttps; _disabled = appHost.ListenWithHttps && netConfig.RequireHttps;
if (_disabled && _config.GetDlnaConfiguration().EnableServer) if (_disabled && _config.GetDlnaConfiguration().EnableServer)
{ {
@ -318,15 +317,9 @@ namespace Emby.Dlna.Main
var fullService = "urn:schemas-upnp-org:device:MediaServer:1"; var fullService = "urn:schemas-upnp-org:device:MediaServer:1";
_logger.LogInformation("Registering publisher for {0} on {1}", fullService, address); _logger.LogInformation("Registering publisher for {ResourceName} on {DeviceAddress}", fullService, address);
var uri = new UriBuilder(_appHost.GetSmartApiUrl(address.Address) + descriptorUri); var uri = new UriBuilder(_appHost.GetApiUrlForLocalAccess(false) + descriptorUri);
if (!string.IsNullOrEmpty(_appHost.PublishedServerUrl))
{
// DLNA will only work over http, so we must reset to http:// : {port}.
uri.Scheme = "http";
uri.Port = _netConfig.HttpServerPortNumber;
}
var device = new SsdpRootDevice var device = new SsdpRootDevice
{ {

View File

@ -1166,10 +1166,13 @@ namespace Emby.Server.Implementations
} }
/// <inheritdoc/> /// <inheritdoc/>
public string GetApiUrlForLocalAccess() public string GetApiUrlForLocalAccess(bool allowHttps)
{ {
string smart = NetManager.GetBindInterface(string.Empty, out var port); // With an empty source, the port will be null
return GetLocalApiUrl(smart.Trim('/'), null, port); string smart = NetManager.GetBindInterface(string.Empty, out _);
var scheme = allowHttps ? Uri.UriSchemeHttps : Uri.UriSchemeHttp;
var port = allowHttps ? HttpsPort : HttpPort;
return GetLocalApiUrl(smart.Trim('/'), scheme, port);
} }
/// <inheritdoc/> /// <inheritdoc/>

View File

@ -81,10 +81,11 @@ namespace MediaBrowser.Controller
string GetSmartApiUrl(string hostname, int? port = null); string GetSmartApiUrl(string hostname, int? port = null);
/// <summary> /// <summary>
/// Gets an URL that can be used to access the API over HTTP (not HTTPS). /// Gets an URL that can be used to access the API over LAN.
/// </summary> /// </summary>
/// <param name="allowHttps">A value indicating whether to allow HTTPS.</param>
/// <returns>The API URL.</returns> /// <returns>The API URL.</returns>
string GetApiUrlForLocalAccess(); string GetApiUrlForLocalAccess(bool allowHttps = true);
/// <summary> /// <summary>
/// Gets a local (LAN) URL that can be used to access the API. /// Gets a local (LAN) URL that can be used to access the API.