Move SyncPlay api to Jellyfin.Api
This commit is contained in:
parent
f7c7b1e7e1
commit
9a2bcd6266
186
Jellyfin.Api/Controllers/SyncPlayController.cs
Normal file
186
Jellyfin.Api/Controllers/SyncPlayController.cs
Normal file
|
@ -0,0 +1,186 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Threading;
|
||||||
|
using Jellyfin.Api.Constants;
|
||||||
|
using Jellyfin.Api.Helpers;
|
||||||
|
using MediaBrowser.Controller.Net;
|
||||||
|
using MediaBrowser.Controller.Session;
|
||||||
|
using MediaBrowser.Controller.SyncPlay;
|
||||||
|
using MediaBrowser.Model.SyncPlay;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The sync play controller.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Policy = Policies.DefaultAuthorization)]
|
||||||
|
public class SyncPlayController : BaseJellyfinApiController
|
||||||
|
{
|
||||||
|
private readonly ISessionManager _sessionManager;
|
||||||
|
private readonly IAuthorizationContext _authorizationContext;
|
||||||
|
private readonly ISyncPlayManager _syncPlayManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SyncPlayController"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionManager">Instance of the <see cref="ISessionManager"/> interface.</param>
|
||||||
|
/// <param name="authorizationContext">Instance of the <see cref="IAuthorizationContext"/> interface.</param>
|
||||||
|
/// <param name="syncPlayManager">Instance of the <see cref="ISyncPlayManager"/> interface.</param>
|
||||||
|
public SyncPlayController(
|
||||||
|
ISessionManager sessionManager,
|
||||||
|
IAuthorizationContext authorizationContext,
|
||||||
|
ISyncPlayManager syncPlayManager)
|
||||||
|
{
|
||||||
|
_sessionManager = sessionManager;
|
||||||
|
_authorizationContext = authorizationContext;
|
||||||
|
_syncPlayManager = syncPlayManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new SyncPlay group.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
||||||
|
[HttpPost("New")]
|
||||||
|
public ActionResult CreateNewGroup()
|
||||||
|
{
|
||||||
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
||||||
|
_syncPlayManager.NewGroup(currentSession, CancellationToken.None);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Join an existing SyncPlay group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId">The sync play group id.</param>
|
||||||
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
||||||
|
[HttpPost("Join")]
|
||||||
|
public ActionResult JoinGroup([FromQuery, Required] Guid groupId)
|
||||||
|
{
|
||||||
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
||||||
|
|
||||||
|
var joinRequest = new JoinGroupRequest()
|
||||||
|
{
|
||||||
|
GroupId = groupId
|
||||||
|
};
|
||||||
|
|
||||||
|
_syncPlayManager.JoinGroup(currentSession, groupId, joinRequest, CancellationToken.None);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Leave the joined SyncPlay group.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
||||||
|
[HttpPost("Leave")]
|
||||||
|
public ActionResult LeaveGroup()
|
||||||
|
{
|
||||||
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
||||||
|
_syncPlayManager.LeaveGroup(currentSession, CancellationToken.None);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all SyncPlay groups.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filterItemId">Optional. Filter by item id.</param>
|
||||||
|
/// <returns>An <see cref="IEnumerable{GrouüInfoView}"/> containing the available SyncPlay groups.</returns>
|
||||||
|
[HttpGet("List")]
|
||||||
|
public ActionResult<IEnumerable<GroupInfoView>> GetSyncPlayGroups([FromQuery] Guid? filterItemId)
|
||||||
|
{
|
||||||
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
||||||
|
return Ok(_syncPlayManager.ListGroups(currentSession, filterItemId.HasValue ? filterItemId.Value : Guid.Empty));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request play in SyncPlay group.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Play()
|
||||||
|
{
|
||||||
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
||||||
|
var syncPlayRequest = new PlaybackRequest()
|
||||||
|
{
|
||||||
|
Type = PlaybackRequestType.Play
|
||||||
|
};
|
||||||
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request pause in SyncPlay group.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Pause()
|
||||||
|
{
|
||||||
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
||||||
|
var syncPlayRequest = new PlaybackRequest()
|
||||||
|
{
|
||||||
|
Type = PlaybackRequestType.Pause
|
||||||
|
};
|
||||||
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request seek in SyncPlay group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="positionTicks">The playback position in ticks.</param>
|
||||||
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Seek([FromQuery] long positionTicks)
|
||||||
|
{
|
||||||
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
||||||
|
var syncPlayRequest = new PlaybackRequest()
|
||||||
|
{
|
||||||
|
Type = PlaybackRequestType.Seek,
|
||||||
|
PositionTicks = positionTicks
|
||||||
|
};
|
||||||
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request group wait in SyncPlay group while buffering.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="when">When the request has been made by the client.</param>
|
||||||
|
/// <param name="positionTicks">The playback position in ticks.</param>
|
||||||
|
/// <param name="bufferingDone">Whether the buffering is done.</param>
|
||||||
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Buffering([FromQuery] DateTime when, [FromQuery] long positionTicks, [FromQuery] bool bufferingDone)
|
||||||
|
{
|
||||||
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
||||||
|
var syncPlayRequest = new PlaybackRequest()
|
||||||
|
{
|
||||||
|
Type = bufferingDone ? PlaybackRequestType.BufferingDone : PlaybackRequestType.Buffering,
|
||||||
|
When = when,
|
||||||
|
PositionTicks = positionTicks
|
||||||
|
};
|
||||||
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update session ping.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ping">The ping.</param>
|
||||||
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Ping([FromQuery] double ping)
|
||||||
|
{
|
||||||
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
||||||
|
var syncPlayRequest = new PlaybackRequest()
|
||||||
|
{
|
||||||
|
Type = PlaybackRequestType.UpdatePing,
|
||||||
|
Ping = Convert.ToInt64(ping)
|
||||||
|
};
|
||||||
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
Jellyfin.Api/Controllers/TimeSyncController.cs
Normal file
39
Jellyfin.Api/Controllers/TimeSyncController.cs
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,302 +0,0 @@
|
||||||
using System.Threading;
|
|
||||||
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("/SyncPlay/{SessionId}/NewGroup", "POST", Summary = "Create a new SyncPlay group")]
|
|
||||||
[Authenticated]
|
|
||||||
public class SyncPlayNewGroup : IReturnVoid
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "SessionId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
|
||||||
public string SessionId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/SyncPlay/{SessionId}/JoinGroup", "POST", Summary = "Join an existing SyncPlay group")]
|
|
||||||
[Authenticated]
|
|
||||||
public class SyncPlayJoinGroup : IReturnVoid
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "SessionId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
|
||||||
public string SessionId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the Group id.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The Group id to join.</value>
|
|
||||||
[ApiMember(Name = "GroupId", Description = "Group Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
||||||
public string GroupId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the playing item id.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The client's currently playing item id.</value>
|
|
||||||
[ApiMember(Name = "PlayingItemId", Description = "Client's playing item id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
||||||
public string PlayingItemId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/SyncPlay/{SessionId}/LeaveGroup", "POST", Summary = "Leave joined SyncPlay group")]
|
|
||||||
[Authenticated]
|
|
||||||
public class SyncPlayLeaveGroup : IReturnVoid
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "SessionId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
|
||||||
public string SessionId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/SyncPlay/{SessionId}/ListGroups", "POST", Summary = "List SyncPlay groups")]
|
|
||||||
[Authenticated]
|
|
||||||
public class SyncPlayListGroups : IReturnVoid
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "SessionId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
|
||||||
public string SessionId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the filter item id.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The filter item id.</value>
|
|
||||||
[ApiMember(Name = "FilterItemId", Description = "Filter by item id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
||||||
public string FilterItemId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/SyncPlay/{SessionId}/PlayRequest", "POST", Summary = "Request play in SyncPlay group")]
|
|
||||||
[Authenticated]
|
|
||||||
public class SyncPlayPlayRequest : IReturnVoid
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "SessionId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
|
||||||
public string SessionId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/SyncPlay/{SessionId}/PauseRequest", "POST", Summary = "Request pause in SyncPlay group")]
|
|
||||||
[Authenticated]
|
|
||||||
public class SyncPlayPauseRequest : IReturnVoid
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "SessionId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
|
||||||
public string SessionId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/SyncPlay/{SessionId}/SeekRequest", "POST", Summary = "Request seek in SyncPlay group")]
|
|
||||||
[Authenticated]
|
|
||||||
public class SyncPlaySeekRequest : IReturnVoid
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "SessionId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
|
||||||
public string SessionId { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "PositionTicks", IsRequired = true, DataType = "long", ParameterType = "query", Verb = "POST")]
|
|
||||||
public long PositionTicks { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/SyncPlay/{SessionId}/BufferingRequest", "POST", Summary = "Request group wait in SyncPlay group while buffering")]
|
|
||||||
[Authenticated]
|
|
||||||
public class SyncPlayBufferingRequest : IReturnVoid
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "SessionId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
|
||||||
public string SessionId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the date used to pin PositionTicks in time.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The date related to PositionTicks.</value>
|
|
||||||
[ApiMember(Name = "When", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
||||||
public string When { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "PositionTicks", IsRequired = true, DataType = "long", ParameterType = "query", Verb = "POST")]
|
|
||||||
public long PositionTicks { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets whether this is a buffering or a buffering-done request.
|
|
||||||
/// </summary>
|
|
||||||
/// <value><c>true</c> if buffering is complete; <c>false</c> otherwise.</value>
|
|
||||||
[ApiMember(Name = "BufferingDone", IsRequired = true, DataType = "bool", ParameterType = "query", Verb = "POST")]
|
|
||||||
public bool BufferingDone { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/SyncPlay/{SessionId}/UpdatePing", "POST", Summary = "Update session ping")]
|
|
||||||
[Authenticated]
|
|
||||||
public class SyncPlayUpdatePing : IReturnVoid
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "SessionId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
|
||||||
public string SessionId { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "Ping", IsRequired = true, DataType = "double", ParameterType = "query", Verb = "POST")]
|
|
||||||
public double Ping { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Class SyncPlayService.
|
|
||||||
/// </summary>
|
|
||||||
public class SyncPlayService : BaseApiService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The session context.
|
|
||||||
/// </summary>
|
|
||||||
private readonly ISessionContext _sessionContext;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The SyncPlay manager.
|
|
||||||
/// </summary>
|
|
||||||
private readonly ISyncPlayManager _syncPlayManager;
|
|
||||||
|
|
||||||
public SyncPlayService(
|
|
||||||
ILogger<SyncPlayService> logger,
|
|
||||||
IServerConfigurationManager serverConfigurationManager,
|
|
||||||
IHttpResultFactory httpResultFactory,
|
|
||||||
ISessionContext sessionContext,
|
|
||||||
ISyncPlayManager syncPlayManager)
|
|
||||||
: base(logger, serverConfigurationManager, httpResultFactory)
|
|
||||||
{
|
|
||||||
_sessionContext = sessionContext;
|
|
||||||
_syncPlayManager = syncPlayManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
public void Post(SyncPlayNewGroup request)
|
|
||||||
{
|
|
||||||
var currentSession = GetSession(_sessionContext);
|
|
||||||
_syncPlayManager.NewGroup(currentSession, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
public void Post(SyncPlayJoinGroup request)
|
|
||||||
{
|
|
||||||
var currentSession = GetSession(_sessionContext);
|
|
||||||
|
|
||||||
Guid groupId;
|
|
||||||
Guid playingItemId = Guid.Empty;
|
|
||||||
|
|
||||||
if (!Guid.TryParse(request.GroupId, out groupId))
|
|
||||||
{
|
|
||||||
Logger.LogError("JoinGroup: {0} is not a valid format for GroupId. Ignoring request.", request.GroupId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Both null and empty strings mean that client isn't playing anything
|
|
||||||
if (!string.IsNullOrEmpty(request.PlayingItemId) && !Guid.TryParse(request.PlayingItemId, out playingItemId))
|
|
||||||
{
|
|
||||||
Logger.LogError("JoinGroup: {0} is not a valid format for PlayingItemId. Ignoring request.", request.PlayingItemId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var joinRequest = new JoinGroupRequest()
|
|
||||||
{
|
|
||||||
GroupId = groupId,
|
|
||||||
PlayingItemId = playingItemId
|
|
||||||
};
|
|
||||||
|
|
||||||
_syncPlayManager.JoinGroup(currentSession, groupId, joinRequest, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
public void Post(SyncPlayLeaveGroup request)
|
|
||||||
{
|
|
||||||
var currentSession = GetSession(_sessionContext);
|
|
||||||
_syncPlayManager.LeaveGroup(currentSession, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
/// <value>The requested list of groups.</value>
|
|
||||||
public List<GroupInfoView> Post(SyncPlayListGroups request)
|
|
||||||
{
|
|
||||||
var currentSession = GetSession(_sessionContext);
|
|
||||||
var filterItemId = Guid.Empty;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.FilterItemId) && !Guid.TryParse(request.FilterItemId, out filterItemId))
|
|
||||||
{
|
|
||||||
Logger.LogWarning("ListGroups: {0} is not a valid format for FilterItemId. Ignoring filter.", request.FilterItemId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _syncPlayManager.ListGroups(currentSession, filterItemId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
public void Post(SyncPlayPlayRequest request)
|
|
||||||
{
|
|
||||||
var currentSession = GetSession(_sessionContext);
|
|
||||||
var syncPlayRequest = new PlaybackRequest()
|
|
||||||
{
|
|
||||||
Type = PlaybackRequestType.Play
|
|
||||||
};
|
|
||||||
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
public void Post(SyncPlayPauseRequest request)
|
|
||||||
{
|
|
||||||
var currentSession = GetSession(_sessionContext);
|
|
||||||
var syncPlayRequest = new PlaybackRequest()
|
|
||||||
{
|
|
||||||
Type = PlaybackRequestType.Pause
|
|
||||||
};
|
|
||||||
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
public void Post(SyncPlaySeekRequest request)
|
|
||||||
{
|
|
||||||
var currentSession = GetSession(_sessionContext);
|
|
||||||
var syncPlayRequest = new PlaybackRequest()
|
|
||||||
{
|
|
||||||
Type = PlaybackRequestType.Seek,
|
|
||||||
PositionTicks = request.PositionTicks
|
|
||||||
};
|
|
||||||
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
public void Post(SyncPlayBufferingRequest request)
|
|
||||||
{
|
|
||||||
var currentSession = GetSession(_sessionContext);
|
|
||||||
var syncPlayRequest = new PlaybackRequest()
|
|
||||||
{
|
|
||||||
Type = request.BufferingDone ? PlaybackRequestType.BufferingDone : PlaybackRequestType.Buffering,
|
|
||||||
When = DateTime.Parse(request.When),
|
|
||||||
PositionTicks = request.PositionTicks
|
|
||||||
};
|
|
||||||
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
public void Post(SyncPlayUpdatePing request)
|
|
||||||
{
|
|
||||||
var currentSession = GetSession(_sessionContext);
|
|
||||||
var syncPlayRequest = new PlaybackRequest()
|
|
||||||
{
|
|
||||||
Type = PlaybackRequestType.UpdatePing,
|
|
||||||
Ping = Convert.ToInt64(request.Ping)
|
|
||||||
};
|
|
||||||
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
using System;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
|
||||||
using MediaBrowser.Controller.Net;
|
|
||||||
using MediaBrowser.Model.Services;
|
|
||||||
using MediaBrowser.Model.SyncPlay;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api.SyncPlay
|
|
||||||
{
|
|
||||||
[Route("/GetUtcTime", "GET", Summary = "Get UtcTime")]
|
|
||||||
public class GetUtcTime : IReturnVoid
|
|
||||||
{
|
|
||||||
// Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Class TimeSyncService.
|
|
||||||
/// </summary>
|
|
||||||
public class TimeSyncService : BaseApiService
|
|
||||||
{
|
|
||||||
public TimeSyncService(
|
|
||||||
ILogger<TimeSyncService> logger,
|
|
||||||
IServerConfigurationManager serverConfigurationManager,
|
|
||||||
IHttpResultFactory httpResultFactory)
|
|
||||||
: base(logger, serverConfigurationManager, httpResultFactory)
|
|
||||||
{
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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;
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user