aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Syncplay/TimeSyncService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api/Syncplay/TimeSyncService.cs')
-rw-r--r--MediaBrowser.Api/Syncplay/TimeSyncService.cs70
1 files changed, 70 insertions, 0 deletions
diff --git a/MediaBrowser.Api/Syncplay/TimeSyncService.cs b/MediaBrowser.Api/Syncplay/TimeSyncService.cs
new file mode 100644
index 0000000000..049684d94c
--- /dev/null
+++ b/MediaBrowser.Api/Syncplay/TimeSyncService.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Net;
+using MediaBrowser.Controller.Session;
+using MediaBrowser.Controller.Syncplay;
+using MediaBrowser.Model.Services;
+using MediaBrowser.Model.Syncplay;
+using Microsoft.Extensions.Logging;
+
+namespace MediaBrowser.Api.Syncplay
+{
+ [Route("/GetUtcTime", "GET", Summary = "Get UtcTime")]
+ [Authenticated]
+ public class GetUtcTime : IReturnVoid
+ {
+ // Nothing
+ }
+
+ /// <summary>
+ /// Class TimeSyncService.
+ /// </summary>
+ public class TimeSyncService : BaseApiService
+ {
+ /// <summary>
+ /// The session manager.
+ /// </summary>
+ private readonly ISessionManager _sessionManager;
+
+ /// <summary>
+ /// The session context.
+ /// </summary>
+ private readonly ISessionContext _sessionContext;
+
+ public TimeSyncService(
+ ILogger<TimeSyncService> logger,
+ IServerConfigurationManager serverConfigurationManager,
+ IHttpResultFactory httpResultFactory,
+ ISessionManager sessionManager,
+ ISessionContext sessionContext)
+ : base(logger, serverConfigurationManager, httpResultFactory)
+ {
+ _sessionManager = sessionManager;
+ _sessionContext = sessionContext;
+ }
+
+ /// <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;
+ var currentSession = GetSession(_sessionContext);
+
+ // Important to keep the following two lines at the end
+ var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime().ToString("o");
+ response.ResponseTransmissionTime = responseTransmissionTime;
+
+ // Implementing NTP on such a high level results in this useless
+ // information being sent. On the other hand it enables future additions.
+ return response;
+ }
+ }
+}