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