jellyfin-server/MediaBrowser.Api/SyncPlay/TimeSyncService.cs

53 lines
1.8 KiB
C#
Raw Normal View History

2020-04-16 14:02:52 +00:00
using System;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Services;
2020-05-06 21:42:53 +00:00
using MediaBrowser.Model.SyncPlay;
2020-04-16 14:02:52 +00:00
using Microsoft.Extensions.Logging;
2020-05-06 21:42:53 +00:00
namespace MediaBrowser.Api.SyncPlay
2020-04-16 14:02:52 +00:00
{
[Route("/GetUtcTime", "GET", Summary = "Get UtcTime")]
public class GetUtcTime : IReturnVoid
{
// Nothing
}
/// <summary>
/// Class TimeSyncService.
/// </summary>
public class TimeSyncService : BaseApiService
{
public TimeSyncService(
ILogger<TimeSyncService> logger,
IServerConfigurationManager serverConfigurationManager,
2020-04-28 12:12:06 +00:00
IHttpResultFactory httpResultFactory)
2020-04-16 14:02:52 +00:00
: base(logger, serverConfigurationManager, httpResultFactory)
{
2020-04-28 12:12:06 +00:00
// Do nothing
2020-04-16 14:02:52 +00:00
}
/// <summary>
/// Handles the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <value>The current UTC time response.</value>
public UtcTimeResponse Get(GetUtcTime request)
{
// Important to keep the following line at the beginning
var requestReceptionTime = DateTime.UtcNow.ToUniversalTime().ToString("o");
var response = new UtcTimeResponse();
response.RequestReceptionTime = requestReceptionTime;
// Important to keep the following two lines at the end
var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime().ToString("o");
response.ResponseTransmissionTime = responseTransmissionTime;
2020-05-04 17:46:02 +00:00
// Implementing NTP on such a high level results in this useless
2020-04-16 14:02:52 +00:00
// information being sent. On the other hand it enables future additions.
return response;
}
}
}