Use DI for SsdpCommunicationsServer

pull/10391/head
Patrick Barron 12 months ago
parent f0618ce335
commit 44380933a0

@ -11,7 +11,10 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Dlna; using MediaBrowser.Controller.Dlna;
using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Net;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Rssdp.Infrastructure;
namespace Emby.Dlna.Extensions; namespace Emby.Dlna.Extensions;
@ -54,5 +57,13 @@ public static class DlnaServiceCollectionExtensions
services.AddSingleton<IContentDirectory, ContentDirectoryService>(); services.AddSingleton<IContentDirectory, ContentDirectoryService>();
services.AddSingleton<IConnectionManager, ConnectionManagerService>(); services.AddSingleton<IConnectionManager, ConnectionManagerService>();
services.AddSingleton<IMediaReceiverRegistrar, MediaReceiverRegistrarService>(); services.AddSingleton<IMediaReceiverRegistrar, MediaReceiverRegistrarService>();
services.AddSingleton<ISsdpCommunicationsServer>(provider => new SsdpCommunicationsServer(
provider.GetRequiredService<ISocketFactory>(),
provider.GetRequiredService<INetworkManager>(),
provider.GetRequiredService<ILogger<SsdpCommunicationsServer>>())
{
IsShared = true
});
} }
} }

@ -25,7 +25,6 @@ using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Net;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Rssdp; using Rssdp;
using Rssdp.Infrastructure; using Rssdp.Infrastructure;
@ -48,14 +47,13 @@ namespace Emby.Dlna.Main
private readonly IMediaSourceManager _mediaSourceManager; private readonly IMediaSourceManager _mediaSourceManager;
private readonly IMediaEncoder _mediaEncoder; private readonly IMediaEncoder _mediaEncoder;
private readonly IDeviceDiscovery _deviceDiscovery; private readonly IDeviceDiscovery _deviceDiscovery;
private readonly ISocketFactory _socketFactory; private readonly ISsdpCommunicationsServer _communicationsServer;
private readonly INetworkManager _networkManager; private readonly INetworkManager _networkManager;
private readonly object _syncLock = new(); private readonly object _syncLock = new();
private readonly bool _disabled; private readonly bool _disabled;
private PlayToManager _manager; private PlayToManager _manager;
private SsdpDevicePublisher _publisher; private SsdpDevicePublisher _publisher;
private ISsdpCommunicationsServer _communicationsServer;
private bool _disposed; private bool _disposed;
@ -74,7 +72,7 @@ namespace Emby.Dlna.Main
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IDeviceDiscovery deviceDiscovery, IDeviceDiscovery deviceDiscovery,
IMediaEncoder mediaEncoder, IMediaEncoder mediaEncoder,
ISocketFactory socketFactory, ISsdpCommunicationsServer communicationsServer,
INetworkManager networkManager) INetworkManager networkManager)
{ {
_config = config; _config = config;
@ -90,7 +88,7 @@ namespace Emby.Dlna.Main
_mediaSourceManager = mediaSourceManager; _mediaSourceManager = mediaSourceManager;
_deviceDiscovery = deviceDiscovery; _deviceDiscovery = deviceDiscovery;
_mediaEncoder = mediaEncoder; _mediaEncoder = mediaEncoder;
_socketFactory = socketFactory; _communicationsServer = communicationsServer;
_networkManager = networkManager; _networkManager = networkManager;
_logger = loggerFactory.CreateLogger<DlnaEntryPoint>(); _logger = loggerFactory.CreateLogger<DlnaEntryPoint>();
@ -129,7 +127,7 @@ namespace Emby.Dlna.Main
private void ReloadComponents() private void ReloadComponents()
{ {
var options = _config.GetDlnaConfiguration(); var options = _config.GetDlnaConfiguration();
StartSsdpHandler(); StartDeviceDiscovery();
if (options.EnableServer) if (options.EnableServer)
{ {
@ -150,37 +148,11 @@ namespace Emby.Dlna.Main
} }
} }
private void StartSsdpHandler() private void StartDeviceDiscovery()
{ {
try try
{ {
if (_communicationsServer is null) ((DeviceDiscovery)_deviceDiscovery).Start(_communicationsServer);
{
_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);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -385,14 +357,6 @@ namespace Emby.Dlna.Main
DisposeDevicePublisher(); DisposeDevicePublisher();
DisposePlayToManager(); DisposePlayToManager();
if (_communicationsServer is not null)
{
_logger.LogInformation("Disposing SsdpCommunicationsServer");
_communicationsServer.Dispose();
_communicationsServer = null;
}
_disposed = true; _disposed = true;
} }
} }

Loading…
Cancel
Save