|
@@ -41,6 +41,7 @@ namespace MediaBrowser.Dlna.Main
|
|
|
private readonly IDeviceDiscovery _deviceDiscovery;
|
|
|
|
|
|
private readonly List<string> _registeredServerIds = new List<string>();
|
|
|
+ private bool _ssdpHandlerStarted;
|
|
|
private bool _dlnaServerStarted;
|
|
|
|
|
|
public DlnaEntryPoint(IServerConfigurationManager config,
|
|
@@ -78,12 +79,22 @@ namespace MediaBrowser.Dlna.Main
|
|
|
|
|
|
public void Run()
|
|
|
{
|
|
|
- StartSsdpHandler();
|
|
|
ReloadComponents();
|
|
|
|
|
|
+ _config.ConfigurationUpdated += _config_ConfigurationUpdated;
|
|
|
_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)
|
|
|
{
|
|
|
if (string.Equals(e.Key, "dlna", StringComparison.OrdinalIgnoreCase))
|
|
@@ -94,10 +105,24 @@ namespace MediaBrowser.Dlna.Main
|
|
|
|
|
|
private void ReloadComponents()
|
|
|
{
|
|
|
- var isServerStarted = _dlnaServerStarted;
|
|
|
-
|
|
|
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)
|
|
|
{
|
|
|
StartDlnaServer();
|
|
@@ -126,6 +151,8 @@ namespace MediaBrowser.Dlna.Main
|
|
|
_ssdpHandler.Start();
|
|
|
|
|
|
((DeviceDiscovery)_deviceDiscovery).Start(_ssdpHandler);
|
|
|
+
|
|
|
+ _ssdpHandlerStarted = true;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -133,6 +160,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()
|
|
|
{
|
|
|
try
|