2
0

TimeSyncService.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Net;
  4. using MediaBrowser.Model.Services;
  5. using MediaBrowser.Model.SyncPlay;
  6. using Microsoft.Extensions.Logging;
  7. namespace MediaBrowser.Api.SyncPlay
  8. {
  9. [Route("/GetUtcTime", "GET", Summary = "Get UtcTime")]
  10. public class GetUtcTime : IReturnVoid
  11. {
  12. // Nothing
  13. }
  14. /// <summary>
  15. /// Class TimeSyncService.
  16. /// </summary>
  17. public class TimeSyncService : BaseApiService
  18. {
  19. public TimeSyncService(
  20. ILogger<TimeSyncService> logger,
  21. IServerConfigurationManager serverConfigurationManager,
  22. IHttpResultFactory httpResultFactory)
  23. : base(logger, serverConfigurationManager, httpResultFactory)
  24. {
  25. // Do nothing
  26. }
  27. /// <summary>
  28. /// Handles the specified request.
  29. /// </summary>
  30. /// <param name="request">The request.</param>
  31. /// <value>The current UTC time response.</value>
  32. public UtcTimeResponse Get(GetUtcTime request)
  33. {
  34. // Important to keep the following line at the beginning
  35. var requestReceptionTime = DateTime.UtcNow.ToUniversalTime().ToString("o");
  36. var response = new UtcTimeResponse();
  37. response.RequestReceptionTime = requestReceptionTime;
  38. // Important to keep the following two lines at the end
  39. var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime().ToString("o");
  40. response.ResponseTransmissionTime = responseTransmissionTime;
  41. // Implementing NTP on such a high level results in this useless
  42. // information being sent. On the other hand it enables future additions.
  43. return response;
  44. }
  45. }
  46. }