aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2023-10-11 13:35:51 -0400
committerPatrick Barron <barronpm@gmail.com>2023-10-11 13:35:51 -0400
commit44380933a0091cba642715395d1b1edd64889120 (patch)
tree2c848a1431112bca9922c9d66c0150d8bca7c56f
parentf0618ce33531dfdcb8d70dc46de309d66903b54e (diff)
Use DI for SsdpCommunicationsServer
-rw-r--r--Emby.Dlna/Extensions/DlnaServiceCollectionExtensions.cs11
-rw-r--r--Emby.Dlna/Main/DlnaEntryPoint.cs48
2 files changed, 17 insertions, 42 deletions
diff --git a/Emby.Dlna/Extensions/DlnaServiceCollectionExtensions.cs b/Emby.Dlna/Extensions/DlnaServiceCollectionExtensions.cs
index 8361cc7e7..32f58cade 100644
--- a/Emby.Dlna/Extensions/DlnaServiceCollectionExtensions.cs
+++ b/Emby.Dlna/Extensions/DlnaServiceCollectionExtensions.cs
@@ -11,7 +11,10 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Model.Dlna;
+using MediaBrowser.Model.Net;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Rssdp.Infrastructure;
namespace Emby.Dlna.Extensions;
@@ -54,5 +57,13 @@ public static class DlnaServiceCollectionExtensions
services.AddSingleton<IContentDirectory, ContentDirectoryService>();
services.AddSingleton<IConnectionManager, ConnectionManagerService>();
services.AddSingleton<IMediaReceiverRegistrar, MediaReceiverRegistrarService>();
+
+ services.AddSingleton<ISsdpCommunicationsServer>(provider => new SsdpCommunicationsServer(
+ provider.GetRequiredService<ISocketFactory>(),
+ provider.GetRequiredService<INetworkManager>(),
+ provider.GetRequiredService<ILogger<SsdpCommunicationsServer>>())
+ {
+ IsShared = true
+ });
}
}
diff --git a/Emby.Dlna/Main/DlnaEntryPoint.cs b/Emby.Dlna/Main/DlnaEntryPoint.cs
index f17e0ca3d..aa7012487 100644
--- a/Emby.Dlna/Main/DlnaEntryPoint.cs
+++ b/Emby.Dlna/Main/DlnaEntryPoint.cs
@@ -25,7 +25,6 @@ using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Globalization;
-using MediaBrowser.Model.Net;
using Microsoft.Extensions.Logging;
using Rssdp;
using Rssdp.Infrastructure;
@@ -48,14 +47,13 @@ namespace Emby.Dlna.Main
private readonly IMediaSourceManager _mediaSourceManager;
private readonly IMediaEncoder _mediaEncoder;
private readonly IDeviceDiscovery _deviceDiscovery;
- private readonly ISocketFactory _socketFactory;
+ private readonly ISsdpCommunicationsServer _communicationsServer;
private readonly INetworkManager _networkManager;
private readonly object _syncLock = new();
private readonly bool _disabled;
private PlayToManager _manager;
private SsdpDevicePublisher _publisher;
- private ISsdpCommunicationsServer _communicationsServer;
private bool _disposed;
@@ -74,7 +72,7 @@ namespace Emby.Dlna.Main
IMediaSourceManager mediaSourceManager,
IDeviceDiscovery deviceDiscovery,
IMediaEncoder mediaEncoder,
- ISocketFactory socketFactory,
+ ISsdpCommunicationsServer communicationsServer,
INetworkManager networkManager)
{
_config = config;
@@ -90,7 +88,7 @@ namespace Emby.Dlna.Main
_mediaSourceManager = mediaSourceManager;
_deviceDiscovery = deviceDiscovery;
_mediaEncoder = mediaEncoder;
- _socketFactory = socketFactory;
+ _communicationsServer = communicationsServer;
_networkManager = networkManager;
_logger = loggerFactory.CreateLogger<DlnaEntryPoint>();
@@ -129,7 +127,7 @@ namespace Emby.Dlna.Main
private void ReloadComponents()
{
var options = _config.GetDlnaConfiguration();
- StartSsdpHandler();
+ StartDeviceDiscovery();
if (options.EnableServer)
{
@@ -150,37 +148,11 @@ namespace Emby.Dlna.Main
}
}
- private void StartSsdpHandler()
+ private void StartDeviceDiscovery()
{
try
{
- if (_communicationsServer is null)
- {
- _communicationsServer = new SsdpCommunicationsServer(
- _socketFactory,
- _networkManager,
- _logger)
- {
- IsShared = true
- };
-
- StartDeviceDiscovery(_communicationsServer);
- }
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Error starting SSDP handlers");
- }
- }
-
- private void StartDeviceDiscovery(ISsdpCommunicationsServer communicationsServer)
- {
- try
- {
- if (communicationsServer is not null)
- {
- ((DeviceDiscovery)_deviceDiscovery).Start(communicationsServer);
- }
+ ((DeviceDiscovery)_deviceDiscovery).Start(_communicationsServer);
}
catch (Exception ex)
{
@@ -385,14 +357,6 @@ namespace Emby.Dlna.Main
DisposeDevicePublisher();
DisposePlayToManager();
-
- if (_communicationsServer is not null)
- {
- _logger.LogInformation("Disposing SsdpCommunicationsServer");
- _communicationsServer.Dispose();
- _communicationsServer = null;
- }
-
_disposed = true;
}
}