mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-24 19:16:32 +00:00
fix live tv over dlna
This commit is contained in:
@@ -393,6 +393,7 @@ namespace Emby.Server.Implementations
|
||||
ISystemEvents systemEvents,
|
||||
INetworkManager networkManager)
|
||||
{
|
||||
|
||||
// hack alert, until common can target .net core
|
||||
BaseExtensions.CryptographyProvider = CryptographyProvider;
|
||||
|
||||
@@ -423,6 +424,13 @@ namespace Emby.Server.Implementations
|
||||
SetBaseExceptionMessage();
|
||||
|
||||
fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));
|
||||
|
||||
NetworkManager.NetworkChanged += NetworkManager_NetworkChanged;
|
||||
}
|
||||
|
||||
private void NetworkManager_NetworkChanged(object sender, EventArgs e)
|
||||
{
|
||||
_validAddressResults.Clear();
|
||||
}
|
||||
|
||||
private Version _version;
|
||||
@@ -1960,9 +1968,9 @@ namespace Emby.Server.Implementations
|
||||
try
|
||||
{
|
||||
// Return the first matched address, if found, or the first known local address
|
||||
var address = (await GetLocalIpAddresses(cancellationToken).ConfigureAwait(false)).FirstOrDefault(i => !i.Equals(IpAddressInfo.Loopback) && !i.Equals(IpAddressInfo.IPv6Loopback));
|
||||
var addresses = await GetLocalIpAddressesInternal(false, 1, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (address != null)
|
||||
foreach (var address in addresses)
|
||||
{
|
||||
return GetLocalApiUrl(address);
|
||||
}
|
||||
@@ -1994,7 +2002,12 @@ namespace Emby.Server.Implementations
|
||||
HttpPort.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public async Task<List<IpAddressInfo>> GetLocalIpAddresses(CancellationToken cancellationToken)
|
||||
public Task<List<IpAddressInfo>> GetLocalIpAddresses(CancellationToken cancellationToken)
|
||||
{
|
||||
return GetLocalIpAddressesInternal(true, 0, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task<List<IpAddressInfo>> GetLocalIpAddressesInternal(bool allowLoopback, int limit, CancellationToken cancellationToken)
|
||||
{
|
||||
var addresses = ServerConfigurationManager
|
||||
.Configuration
|
||||
@@ -2006,22 +2019,33 @@ namespace Emby.Server.Implementations
|
||||
if (addresses.Count == 0)
|
||||
{
|
||||
addresses.AddRange(NetworkManager.GetLocalIpAddresses());
|
||||
}
|
||||
|
||||
var list = new List<IpAddressInfo>();
|
||||
var resultList = new List<IpAddressInfo>();
|
||||
|
||||
foreach (var address in addresses)
|
||||
foreach (var address in addresses)
|
||||
{
|
||||
if (!allowLoopback)
|
||||
{
|
||||
var valid = await IsIpAddressValidAsync(address, cancellationToken).ConfigureAwait(false);
|
||||
if (valid)
|
||||
if (address.Equals(IpAddressInfo.Loopback) || address.Equals(IpAddressInfo.IPv6Loopback))
|
||||
{
|
||||
list.Add(address);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
addresses = list;
|
||||
var valid = await IsIpAddressValidAsync(address, cancellationToken).ConfigureAwait(false);
|
||||
if (valid)
|
||||
{
|
||||
resultList.Add(address);
|
||||
|
||||
if (limit > 0 && resultList.Count >= limit)
|
||||
{
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return addresses;
|
||||
return resultList;
|
||||
}
|
||||
|
||||
private IpAddressInfo NormalizeConfiguredLocalAddress(string address)
|
||||
@@ -2042,7 +2066,6 @@ namespace Emby.Server.Implementations
|
||||
}
|
||||
|
||||
private readonly ConcurrentDictionary<string, bool> _validAddressResults = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
|
||||
private DateTime _lastAddressCacheClear;
|
||||
private async Task<bool> IsIpAddressValidAsync(IpAddressInfo address, CancellationToken cancellationToken)
|
||||
{
|
||||
if (address.Equals(IpAddressInfo.Loopback) ||
|
||||
@@ -2054,12 +2077,6 @@ namespace Emby.Server.Implementations
|
||||
var apiUrl = GetLocalApiUrl(address);
|
||||
apiUrl += "/system/ping";
|
||||
|
||||
if ((DateTime.UtcNow - _lastAddressCacheClear).TotalMinutes >= 15)
|
||||
{
|
||||
_lastAddressCacheClear = DateTime.UtcNow;
|
||||
_validAddressResults.Clear();
|
||||
}
|
||||
|
||||
bool cachedResult;
|
||||
if (_validAddressResults.TryGetValue(apiUrl, out cachedResult))
|
||||
{
|
||||
@@ -2087,18 +2104,19 @@ namespace Emby.Server.Implementations
|
||||
var valid = string.Equals(Name, result, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
_validAddressResults.AddOrUpdate(apiUrl, valid, (k, v) => valid);
|
||||
//Logger.Debug("Ping test result to {0}. Success: {1}", apiUrl, valid);
|
||||
Logger.Debug("Ping test result to {0}. Success: {1}", apiUrl, valid);
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Logger.Debug("Ping test result to {0}. Success: {1}", apiUrl, "Cancelled");
|
||||
throw;
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Logger.Debug("Ping test result to {0}. Success: {1}", apiUrl, false);
|
||||
Logger.Debug("Ping test result to {0}. Success: {1}", apiUrl, false);
|
||||
|
||||
_validAddressResults.AddOrUpdate(apiUrl, false, (k, v) => false);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user