TimeSyncController.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using MediaBrowser.Model.SyncPlay;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. namespace Jellyfin.Api.Controllers
  6. {
  7. /// <summary>
  8. /// The time sync controller.
  9. /// </summary>
  10. [Route("")]
  11. public class TimeSyncController : BaseJellyfinApiController
  12. {
  13. /// <summary>
  14. /// Gets the current UTC time.
  15. /// </summary>
  16. /// <response code="200">Time returned.</response>
  17. /// <returns>An <see cref="UtcTimeResponse"/> to sync the client and server time.</returns>
  18. [HttpGet("GetUtcTime")]
  19. [ProducesResponseType(statusCode: StatusCodes.Status200OK)]
  20. public ActionResult<UtcTimeResponse> GetUtcTime()
  21. {
  22. // Important to keep the following line at the beginning
  23. var requestReceptionTime = DateTime.UtcNow.ToUniversalTime();
  24. // Important to keep the following line at the end
  25. var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime();
  26. // Implementing NTP on such a high level results in this useless
  27. // information being sent. On the other hand it enables future additions.
  28. return new UtcTimeResponse(requestReceptionTime, responseTransmissionTime);
  29. }
  30. }
  31. }