mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-04 06:48:35 +01:00
rework hosting options
This commit is contained in:
@@ -184,8 +184,9 @@ namespace MediaBrowser.Server.Implementations.Collections
|
||||
|
||||
collection.LinkedChildren.AddRange(list);
|
||||
|
||||
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
||||
collection.UpdateRatingToContent();
|
||||
|
||||
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
||||
await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
if (fireEvent)
|
||||
@@ -274,8 +275,9 @@ namespace MediaBrowser.Server.Implementations.Collections
|
||||
}
|
||||
}
|
||||
|
||||
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
||||
collection.UpdateRatingToContent();
|
||||
|
||||
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
||||
await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
EventHelper.FireEventIfNotNull(ItemsRemovedFromCollection, this, new CollectionModifiedEventArgs
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
if (!ip.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
|
||||
!ip.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ip = (_config.Configuration.UseHttps ? "https://" : "http://") + ip;
|
||||
ip = (_appHost.EnableHttps ? "https://" : "http://") + ip;
|
||||
}
|
||||
|
||||
return ip + ":" + _config.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture);
|
||||
@@ -90,7 +90,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
|
||||
private string XApplicationValue
|
||||
{
|
||||
get { return "Media Browser Server/" + _appHost.ApplicationVersion; }
|
||||
get { return _appHost.Name + "/" + _appHost.ApplicationVersion; }
|
||||
}
|
||||
|
||||
public ConnectManager(ILogger logger,
|
||||
@@ -112,6 +112,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
_providerManager = providerManager;
|
||||
|
||||
_userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated;
|
||||
_config.ConfigurationUpdated += _config_ConfigurationUpdated;
|
||||
|
||||
LoadCachedData();
|
||||
}
|
||||
@@ -164,8 +165,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
}
|
||||
catch (HttpException ex)
|
||||
{
|
||||
if (!ex.StatusCode.HasValue ||
|
||||
!new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value))
|
||||
if (!ex.StatusCode.HasValue || !new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -179,6 +179,8 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
await CreateServerRegistration(wanApiAddress, localAddress).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
_lastReportedIdentifier = GetConnectReportingIdentifier(localAddress, wanApiAddress);
|
||||
|
||||
await RefreshAuthorizationsInternal(true, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -187,6 +189,27 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
}
|
||||
}
|
||||
|
||||
private string _lastReportedIdentifier;
|
||||
private string GetConnectReportingIdentifier()
|
||||
{
|
||||
return GetConnectReportingIdentifier(_appHost.GetSystemInfo().LocalAddress, WanApiAddress);
|
||||
}
|
||||
private string GetConnectReportingIdentifier(string localAddress, string remoteAddress)
|
||||
{
|
||||
return (remoteAddress ?? string.Empty) + (localAddress ?? string.Empty);
|
||||
}
|
||||
|
||||
void _config_ConfigurationUpdated(object sender, EventArgs e)
|
||||
{
|
||||
// If info hasn't changed, don't report anything
|
||||
if (string.Equals(_lastReportedIdentifier, GetConnectReportingIdentifier(), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateConnectInfo();
|
||||
}
|
||||
|
||||
private async Task CreateServerRegistration(string wanApiAddress, string localAddress)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(wanApiAddress))
|
||||
|
||||
@@ -5,6 +5,7 @@ using MediaBrowser.Model.Logging;
|
||||
using Mono.Nat;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -17,30 +18,44 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
||||
private readonly ILogger _logger;
|
||||
private readonly IServerConfigurationManager _config;
|
||||
|
||||
private bool _isStarted;
|
||||
|
||||
private Timer _timer;
|
||||
private bool _isStarted;
|
||||
|
||||
public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config)
|
||||
{
|
||||
_logger = logmanager.GetLogger("PortMapper");
|
||||
_appHost = appHost;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
_config.ConfigurationUpdated += _config_ConfigurationUpdated;
|
||||
private string _lastConfigIdentifier;
|
||||
private string GetConfigIdentifier()
|
||||
{
|
||||
var values = new List<string>();
|
||||
var config = _config.Configuration;
|
||||
|
||||
values.Add(config.EnableUPnP.ToString());
|
||||
values.Add(config.PublicPort.ToString(CultureInfo.InvariantCulture));
|
||||
values.Add(_appHost.HttpPort.ToString(CultureInfo.InvariantCulture));
|
||||
values.Add(_appHost.HttpsPort.ToString(CultureInfo.InvariantCulture));
|
||||
values.Add(config.EnableHttps.ToString());
|
||||
values.Add(_appHost.EnableHttps.ToString());
|
||||
|
||||
return string.Join("|", values.ToArray());
|
||||
}
|
||||
|
||||
void _config_ConfigurationUpdated(object sender, EventArgs e)
|
||||
{
|
||||
var enable = _config.Configuration.EnableUPnP;
|
||||
_config.ConfigurationUpdated -= _config_ConfigurationUpdated;
|
||||
|
||||
if (!string.Equals(_lastConfigIdentifier, GetConfigIdentifier(), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (_isStarted)
|
||||
{
|
||||
DisposeNat();
|
||||
}
|
||||
|
||||
if (enable && !_isStarted)
|
||||
{
|
||||
Reload();
|
||||
}
|
||||
else if (!enable && _isStarted)
|
||||
{
|
||||
DisposeNat();
|
||||
Run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,31 +63,36 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
||||
{
|
||||
//NatUtility.Logger = new LogWriter(_logger);
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
private void Reload()
|
||||
{
|
||||
if (_config.Configuration.EnableUPnP)
|
||||
{
|
||||
_logger.Debug("Starting NAT discovery");
|
||||
|
||||
NatUtility.DeviceFound += NatUtility_DeviceFound;
|
||||
|
||||
// Mono.Nat does never rise this event. The event is there however it is useless.
|
||||
// You could remove it with no risk.
|
||||
NatUtility.DeviceLost += NatUtility_DeviceLost;
|
||||
|
||||
|
||||
// it is hard to say what one should do when an unhandled exception is raised
|
||||
// because there isn't anything one can do about it. Probably save a log or ignored it.
|
||||
NatUtility.UnhandledException += NatUtility_UnhandledException;
|
||||
NatUtility.StartDiscovery();
|
||||
|
||||
_isStarted = true;
|
||||
|
||||
_timer = new Timer(s => _createdRules = new List<string>(), null, TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));
|
||||
Start();
|
||||
}
|
||||
|
||||
_config.ConfigurationUpdated -= _config_ConfigurationUpdated;
|
||||
_config.ConfigurationUpdated += _config_ConfigurationUpdated;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_logger.Debug("Starting NAT discovery");
|
||||
|
||||
NatUtility.DeviceFound += NatUtility_DeviceFound;
|
||||
|
||||
// Mono.Nat does never rise this event. The event is there however it is useless.
|
||||
// You could remove it with no risk.
|
||||
NatUtility.DeviceLost += NatUtility_DeviceLost;
|
||||
|
||||
|
||||
// it is hard to say what one should do when an unhandled exception is raised
|
||||
// because there isn't anything one can do about it. Probably save a log or ignored it.
|
||||
NatUtility.UnhandledException += NatUtility_UnhandledException;
|
||||
NatUtility.StartDiscovery();
|
||||
|
||||
_timer = new Timer(s => _createdRules = new List<string>(), null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
|
||||
|
||||
_lastConfigIdentifier = GetConfigIdentifier();
|
||||
|
||||
_isStarted = true;
|
||||
}
|
||||
|
||||
void NatUtility_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
@@ -124,9 +144,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
||||
{
|
||||
_createdRules.Add(address);
|
||||
|
||||
var info = _appHost.GetSystemInfo();
|
||||
|
||||
CreatePortMap(device, info.HttpServerPortNumber, _config.Configuration.PublicPort);
|
||||
CreatePortMap(device, _appHost.HttpPort, _config.Configuration.PublicPort);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +154,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
||||
|
||||
device.CreatePortMap(new Mapping(Protocol.Tcp, privatePort, publicPort)
|
||||
{
|
||||
Description = "Media Browser Server"
|
||||
Description = _appHost.Name
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using MediaBrowser.Common;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Server.Implementations.HttpServer.NetListener;
|
||||
using MediaBrowser.Server.Implementations.HttpServer.SocketSharp;
|
||||
using ServiceStack;
|
||||
using ServiceStack.Api.Swagger;
|
||||
@@ -41,7 +40,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
|
||||
private readonly ReaderWriterLockSlim _localEndpointLock = new ReaderWriterLockSlim();
|
||||
|
||||
private string _certificatePath;
|
||||
public string CertificatePath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the local end points.
|
||||
@@ -206,7 +205,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
|
||||
private IHttpListener GetListener()
|
||||
{
|
||||
return new WebSocketSharpListener(_logger, OnRequestReceived, _certificatePath);
|
||||
return new WebSocketSharpListener(_logger, OnRequestReceived, CertificatePath);
|
||||
}
|
||||
|
||||
private void WebSocketHandler(WebSocketConnectEventArgs args)
|
||||
@@ -434,7 +433,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
|
||||
public void StartServer(IEnumerable<string> urlPrefixes, string certificatePath)
|
||||
{
|
||||
_certificatePath = certificatePath;
|
||||
CertificatePath = certificatePath;
|
||||
UrlPrefixes = urlPrefixes.ToList();
|
||||
Start(UrlPrefixes.First());
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Server.Implementations.Logging;
|
||||
using ServiceStack;
|
||||
using ServiceStack.Web;
|
||||
using SocketHttpListener.Net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SocketHttpListener.Net;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||
{
|
||||
|
||||
@@ -192,9 +192,10 @@
|
||||
"LabelPlayMethodDirectPlay": "Direct Playing",
|
||||
"LabelAudioCodec": "Audio: {0}",
|
||||
"LabelVideoCodec": "Video: {0}",
|
||||
"LabelLocalAccessUrl": "Local access: {0}",
|
||||
"LabelRemoteAccessUrl": "Remote access: {0}",
|
||||
"LabelRunningOnPort": "Running on port {0}.",
|
||||
"LabelRunningOnHttpsPort": "Running on SSL port {0}.",
|
||||
"LabelRunningOnPort": "Running on http port {0}.",
|
||||
"LabelRunningOnPorts": "Running on http port {0}, and https port {1}.",
|
||||
"HeaderLatestFromChannel": "Latest from {0}",
|
||||
"ButtonDownload": "Download",
|
||||
"LabelUnknownLanaguage": "Unknown language",
|
||||
|
||||
@@ -519,19 +519,17 @@
|
||||
"LabelLocalHttpServerPortNumberHelp": "The tcp port number that Media Browser's http server should bind to.",
|
||||
"LabelPublicPort": "Public port number:",
|
||||
"LabelPublicPortHelp": "The public port number that should be mapped to the local port.",
|
||||
|
||||
"LabelUseHttps": "Enable SSL",
|
||||
"LabelUseHttpsHelp": "Check to enable SSL hosting.",
|
||||
"LabelHttpsPort": "Local http port:",
|
||||
"LabelEnableHttps": "Enable https for remote connections",
|
||||
"LabelEnableHttpsHelp": "If enabled, the server will report an https url as it's external address.",
|
||||
"LabelHttpsPort": "Local https port:",
|
||||
"LabelHttpsPortHelp": "The tcp port number that Media Browser's https server should bind to.",
|
||||
"LabelCertificatePath": "SSL Certificate path:",
|
||||
"LabelCertificatePathHelp": "The path on the filesystem to the ssl certificate pfx file.",
|
||||
|
||||
"LabelCertificatePathHelp": "The path on the file system to the ssl certificate .pfx file.",
|
||||
"LabelWebSocketPortNumber": "Web socket port number:",
|
||||
"LabelEnableAutomaticPortMap": "Enable automatic port mapping",
|
||||
"LabelEnableAutomaticPortMapHelp": "Attempt to automatically map the public port to the local port via UPnP. This may not work with some router models.",
|
||||
"LabelExternalDDNS": "External DDNS:",
|
||||
"LabelExternalDDNSHelp": "If you have a dynamic DNS enter it here. Media Browser apps will use it when connecting remotely.",
|
||||
"LabelExternalDDNS": "External WAN Address:",
|
||||
"LabelExternalDDNSHelp": "If you have a dynamic DNS enter it here. Media Browser apps will use it when connecting remotely. Leave empty for automatic detection.",
|
||||
"TabResume": "Resume",
|
||||
"TabWeather": "Weather",
|
||||
"TitleAppSettings": "App Settings",
|
||||
@@ -600,6 +598,7 @@
|
||||
"ButtonRestart": "Restart",
|
||||
"ButtonShutdown": "Shutdown",
|
||||
"ButtonUpdateNow": "Update Now",
|
||||
"TabHosting": "Hosting",
|
||||
"PleaseUpdateManually": "Please shutdown the server and update manually.",
|
||||
"NewServerVersionAvailable": "A new version of Media Browser Server is available!",
|
||||
"ServerUpToDate": "Media Browser Server is up to date",
|
||||
|
||||
Reference in New Issue
Block a user