aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Controllers/TimeSyncController.cs
diff options
context:
space:
mode:
authorDavid <daullmer@gmail.com>2020-07-15 16:15:17 +0200
committerDavid <daullmer@gmail.com>2020-07-15 16:15:17 +0200
commit9a2bcd6266fb222491abe6ea31d5e7e734699d5f (patch)
treee9182ef0dd6e31b288cb48d83d487cee83685d9c /Jellyfin.Api/Controllers/TimeSyncController.cs
parentf7c7b1e7e15678bb8ba92f082b9bc2882c87baae (diff)
Move SyncPlay api to Jellyfin.Api
Diffstat (limited to 'Jellyfin.Api/Controllers/TimeSyncController.cs')
-rw-r--r--Jellyfin.Api/Controllers/TimeSyncController.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/Jellyfin.Api/Controllers/TimeSyncController.cs b/Jellyfin.Api/Controllers/TimeSyncController.cs
new file mode 100644
index 000000000..57a720b26
--- /dev/null
+++ b/Jellyfin.Api/Controllers/TimeSyncController.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Globalization;
+using MediaBrowser.Model.SyncPlay;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Jellyfin.Api.Controllers
+{
+ /// <summary>
+ /// The time sync controller.
+ /// </summary>
+ [Route("/GetUtcTime")]
+ public class TimeSyncController : BaseJellyfinApiController
+ {
+ /// <summary>
+ /// Gets the current utc time.
+ /// </summary>
+ /// <response code="200">Time returned.</response>
+ /// <returns>An <see cref="UtcTimeResponse"/> to sync the client and server time.</returns>
+ [HttpGet]
+ [ProducesResponseType(statusCode: StatusCodes.Status200OK)]
+ public ActionResult<UtcTimeResponse> GetUtcTime()
+ {
+ // Important to keep the following line at the beginning
+ var requestReceptionTime = DateTime.UtcNow.ToUniversalTime().ToString("o", DateTimeFormatInfo.InvariantInfo);
+
+ var response = new UtcTimeResponse();
+ response.RequestReceptionTime = requestReceptionTime;
+
+ // Important to keep the following two lines at the end
+ var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime().ToString("o", DateTimeFormatInfo.InvariantInfo);
+ 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;
+ }
+ }
+}