2019-01-13 20:54:44 +01:00
|
|
|
using System;
|
2019-01-27 15:40:37 +01:00
|
|
|
using System.Threading.Tasks;
|
2019-01-13 20:20:41 +01:00
|
|
|
using Emby.Server.Implementations.Udp;
|
2014-07-28 00:01:29 +02:00
|
|
|
using MediaBrowser.Controller;
|
2013-05-19 00:07:59 +02:00
|
|
|
using MediaBrowser.Controller.Plugins;
|
2016-11-04 19:56:47 +01:00
|
|
|
using MediaBrowser.Model.Net;
|
2019-01-13 20:20:41 +01:00
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2013-05-19 00:07:59 +02:00
|
|
|
|
2016-11-04 19:56:47 +01:00
|
|
|
namespace Emby.Server.Implementations.EntryPoints
|
2013-05-19 00:07:59 +02:00
|
|
|
{
|
2013-05-27 20:34:03 +02:00
|
|
|
/// <summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
/// Class UdpServerEntryPoint.
|
2013-05-27 20:34:03 +02:00
|
|
|
/// </summary>
|
2013-05-19 00:07:59 +02:00
|
|
|
public class UdpServerEntryPoint : IServerEntryPoint
|
|
|
|
{
|
|
|
|
/// <summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
/// The port of the UDP server.
|
2013-05-19 00:07:59 +02:00
|
|
|
/// </summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
public const int PortNumber = 7359;
|
2013-05-19 00:07:59 +02:00
|
|
|
|
2013-05-27 20:34:03 +02:00
|
|
|
/// <summary>
|
2019-12-10 16:22:03 +01:00
|
|
|
/// The logger.
|
2013-05-27 20:34:03 +02:00
|
|
|
/// </summary>
|
2013-05-19 00:07:59 +02:00
|
|
|
private readonly ILogger _logger;
|
2016-11-04 19:56:47 +01:00
|
|
|
private readonly ISocketFactory _socketFactory;
|
2014-07-28 00:01:29 +02:00
|
|
|
private readonly IServerApplicationHost _appHost;
|
2014-07-30 05:31:35 +02:00
|
|
|
private readonly IJsonSerializer _json;
|
2013-05-19 00:07:59 +02:00
|
|
|
|
2019-11-01 18:38:54 +01:00
|
|
|
/// <summary>
|
|
|
|
/// The UDP server.
|
|
|
|
/// </summary>
|
|
|
|
private UdpServer _udpServer;
|
2013-09-25 02:54:51 +02:00
|
|
|
|
2013-05-27 20:34:03 +02:00
|
|
|
/// <summary>
|
2014-08-20 00:28:35 +02:00
|
|
|
/// Initializes a new instance of the <see cref="UdpServerEntryPoint" /> class.
|
2013-05-27 20:34:03 +02:00
|
|
|
/// </summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
public UdpServerEntryPoint(
|
|
|
|
ILogger logger,
|
|
|
|
IServerApplicationHost appHost,
|
|
|
|
IJsonSerializer json,
|
|
|
|
ISocketFactory socketFactory)
|
2013-05-19 00:07:59 +02:00
|
|
|
{
|
|
|
|
_logger = logger;
|
2014-07-28 00:01:29 +02:00
|
|
|
_appHost = appHost;
|
2014-07-30 05:31:35 +02:00
|
|
|
_json = json;
|
2016-11-04 19:56:47 +01:00
|
|
|
_socketFactory = socketFactory;
|
2013-05-19 00:07:59 +02:00
|
|
|
}
|
2013-05-27 20:34:03 +02:00
|
|
|
|
2019-11-01 18:38:54 +01:00
|
|
|
/// <inheritdoc />
|
2019-01-27 15:40:37 +01:00
|
|
|
public Task RunAsync()
|
2013-05-19 00:07:59 +02:00
|
|
|
{
|
2016-11-04 19:56:47 +01:00
|
|
|
var udpServer = new UdpServer(_logger, _appHost, _json, _socketFactory);
|
2013-05-19 00:07:59 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2013-09-25 02:54:51 +02:00
|
|
|
udpServer.Start(PortNumber);
|
2013-05-19 00:07:59 +02:00
|
|
|
|
2019-11-01 18:38:54 +01:00
|
|
|
_udpServer = udpServer;
|
2013-05-19 00:07:59 +02:00
|
|
|
}
|
2016-11-04 15:09:21 +01:00
|
|
|
catch (Exception ex)
|
2013-05-19 00:07:59 +02:00
|
|
|
{
|
2018-12-20 13:11:26 +01:00
|
|
|
_logger.LogError(ex, "Failed to start UDP Server");
|
2013-05-19 00:07:59 +02:00
|
|
|
}
|
2019-01-27 15:40:37 +01:00
|
|
|
|
|
|
|
return Task.CompletedTask;
|
2013-05-19 00:07:59 +02:00
|
|
|
}
|
|
|
|
|
2019-11-01 18:38:54 +01:00
|
|
|
/// <inheritdoc />
|
2013-05-19 00:07:59 +02:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
2019-11-01 18:38:54 +01:00
|
|
|
GC.SuppressFinalize(this);
|
2013-05-19 00:07:59 +02:00
|
|
|
}
|
|
|
|
|
2013-05-27 20:34:03 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Releases unmanaged and - optionally - managed resources.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
2013-05-19 00:07:59 +02:00
|
|
|
protected virtual void Dispose(bool dispose)
|
|
|
|
{
|
|
|
|
if (dispose)
|
|
|
|
{
|
2019-11-01 18:38:54 +01:00
|
|
|
if (_udpServer != null)
|
2013-05-19 00:07:59 +02:00
|
|
|
{
|
2019-11-01 18:38:54 +01:00
|
|
|
_udpServer.Dispose();
|
2013-05-19 00:07:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|