Dlna: Stop SSDP if disabled, Fixes #1578

This commit is contained in:
nfnty 2016-04-21 08:02:23 +02:00
parent c59b4329f4
commit 1bb287ccff

View File

@ -39,6 +39,7 @@ namespace MediaBrowser.Dlna.Main
private readonly IDeviceDiscovery _deviceDiscovery; private readonly IDeviceDiscovery _deviceDiscovery;
private readonly List<string> _registeredServerIds = new List<string>(); private readonly List<string> _registeredServerIds = new List<string>();
private bool _ssdpHandlerStarted;
private bool _dlnaServerStarted; private bool _dlnaServerStarted;
public DlnaEntryPoint(IServerConfigurationManager config, public DlnaEntryPoint(IServerConfigurationManager config,
@ -75,12 +76,22 @@ namespace MediaBrowser.Dlna.Main
public void Run() public void Run()
{ {
StartSsdpHandler();
ReloadComponents(); ReloadComponents();
_config.ConfigurationUpdated += _config_ConfigurationUpdated;
_config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated; _config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated;
} }
private bool _lastEnableUPnP;
void _config_ConfigurationUpdated(object sender, EventArgs e)
{
if (_lastEnableUPnP != _config.Configuration.EnableUPnP)
{
ReloadComponents();
}
_lastEnableUPnP = _config.Configuration.EnableUPnP;
}
void _config_NamedConfigurationUpdated(object sender, ConfigurationUpdateEventArgs e) void _config_NamedConfigurationUpdated(object sender, ConfigurationUpdateEventArgs e)
{ {
if (string.Equals(e.Key, "dlna", StringComparison.OrdinalIgnoreCase)) if (string.Equals(e.Key, "dlna", StringComparison.OrdinalIgnoreCase))
@ -91,10 +102,24 @@ namespace MediaBrowser.Dlna.Main
private void ReloadComponents() private void ReloadComponents()
{ {
var isServerStarted = _dlnaServerStarted;
var options = _config.GetDlnaConfiguration(); var options = _config.GetDlnaConfiguration();
if (!options.EnableServer && !options.EnablePlayTo && !_config.Configuration.EnableUPnP)
{
if (_ssdpHandlerStarted)
{
StopSsdpHandler();
}
return;
}
if (!_ssdpHandlerStarted)
{
StartSsdpHandler();
}
var isServerStarted = _dlnaServerStarted;
if (options.EnableServer && !isServerStarted) if (options.EnableServer && !isServerStarted)
{ {
StartDlnaServer(); StartDlnaServer();
@ -123,6 +148,8 @@ namespace MediaBrowser.Dlna.Main
_ssdpHandler.Start(); _ssdpHandler.Start();
((DeviceDiscovery)_deviceDiscovery).Start(_ssdpHandler); ((DeviceDiscovery)_deviceDiscovery).Start(_ssdpHandler);
_ssdpHandlerStarted = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -130,6 +157,22 @@ namespace MediaBrowser.Dlna.Main
} }
} }
private void StopSsdpHandler()
{
try
{
((DeviceDiscovery)_deviceDiscovery).Dispose();
_ssdpHandler.Dispose();
_ssdpHandlerStarted = false;
}
catch (Exception ex)
{
_logger.ErrorException("Error stopping ssdp handlers", ex);
}
}
public void StartDlnaServer() public void StartDlnaServer()
{ {
try try