2020-11-21 13:26:03 +00:00
|
|
|
using System;
|
2020-07-15 14:15:17 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Threading;
|
|
|
|
using Jellyfin.Api.Constants;
|
|
|
|
using Jellyfin.Api.Helpers;
|
2020-12-03 18:01:57 +00:00
|
|
|
using Jellyfin.Api.Models.SyncPlayDtos;
|
2020-07-15 14:15:17 +00:00
|
|
|
using MediaBrowser.Controller.Net;
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
using MediaBrowser.Controller.SyncPlay;
|
2020-11-14 22:40:01 +00:00
|
|
|
using MediaBrowser.Controller.SyncPlay.PlaybackRequests;
|
2020-11-28 15:03:02 +00:00
|
|
|
using MediaBrowser.Controller.SyncPlay.Requests;
|
2020-07-15 14:15:17 +00:00
|
|
|
using MediaBrowser.Model.SyncPlay;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-07-22 08:20:51 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2020-07-15 14:15:17 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The sync play controller.
|
|
|
|
/// </summary>
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayHasAccess)]
|
2020-07-15 14:15:17 +00:00
|
|
|
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>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The settings of the new group.</param>
|
2020-07-22 08:20:51 +00:00
|
|
|
/// <response code="204">New group created.</response>
|
2020-07-15 14:15:17 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("New")]
|
2020-07-22 08:20:51 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayCreateGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlayCreateGroup(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] NewGroupRequestDto requestData)
|
2020-07-15 14:15:17 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 15:03:02 +00:00
|
|
|
var syncPlayRequest = new NewGroupRequest(requestData.GroupName);
|
|
|
|
_syncPlayManager.NewGroup(currentSession, syncPlayRequest, CancellationToken.None);
|
2020-07-15 14:15:17 +00:00
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Join an existing SyncPlay group.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The group to join.</param>
|
2020-07-22 08:20:51 +00:00
|
|
|
/// <response code="204">Group join successful.</response>
|
2020-07-15 14:15:17 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("Join")]
|
2020-07-22 08:20:51 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayJoinGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlayJoinGroup(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] JoinGroupRequestDto requestData)
|
2020-07-15 14:15:17 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 15:03:02 +00:00
|
|
|
var syncPlayRequest = new JoinGroupRequest(requestData.GroupId);
|
|
|
|
_syncPlayManager.JoinGroup(currentSession, syncPlayRequest, CancellationToken.None);
|
2020-07-15 14:15:17 +00:00
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Leave the joined SyncPlay group.
|
|
|
|
/// </summary>
|
2020-07-22 08:20:51 +00:00
|
|
|
/// <response code="204">Group leave successful.</response>
|
2020-07-15 14:15:17 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("Leave")]
|
2020-07-22 08:20:51 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-08-03 20:38:51 +00:00
|
|
|
public ActionResult SyncPlayLeaveGroup()
|
2020-07-15 14:15:17 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 15:03:02 +00:00
|
|
|
var syncPlayRequest = new LeaveGroupRequest();
|
|
|
|
_syncPlayManager.LeaveGroup(currentSession, syncPlayRequest, CancellationToken.None);
|
2020-07-15 14:15:17 +00:00
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets all SyncPlay groups.
|
|
|
|
/// </summary>
|
2020-07-22 08:20:51 +00:00
|
|
|
/// <response code="200">Groups returned.</response>
|
2020-08-06 14:17:45 +00:00
|
|
|
/// <returns>An <see cref="IEnumerable{GroupInfoView}"/> containing the available SyncPlay groups.</returns>
|
2020-07-15 14:15:17 +00:00
|
|
|
[HttpGet("List")]
|
2020-07-22 08:20:51 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayJoinGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult<IEnumerable<GroupInfoDto>> SyncPlayGetGroups()
|
2020-07-15 14:15:17 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 15:03:02 +00:00
|
|
|
var syncPlayRequest = new ListGroupsRequest();
|
|
|
|
return Ok(_syncPlayManager.ListGroups(currentSession, syncPlayRequest));
|
2020-07-15 14:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// Request to set new playlist in SyncPlay group.
|
2020-07-15 14:15:17 +00:00
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The new playlist to play in the group.</param>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <response code="204">Queue update sent to all group members.</response>
|
2020-07-15 14:15:17 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
2020-12-03 14:41:34 +00:00
|
|
|
[HttpPost("SetNewQueue")]
|
2020-07-22 08:20:51 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-12-03 14:41:34 +00:00
|
|
|
public ActionResult SyncPlaySetNewQueue(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] PlayRequestDto requestData)
|
2020-09-24 21:04:21 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new PlayGroupRequest(
|
|
|
|
requestData.PlayingQueue,
|
|
|
|
requestData.PlayingItemPosition,
|
|
|
|
requestData.StartPositionTicks);
|
2020-09-24 21:04:21 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Request to change playlist item in SyncPlay group.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The new item to play.</param>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <response code="204">Queue update sent to all group members.</response>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("SetPlaylistItem")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlaySetPlaylistItem(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] SetPlaylistItemRequestDto requestData)
|
2020-09-24 21:04:21 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new SetPlaylistItemGroupRequest(requestData.PlaylistItemId);
|
2020-09-24 21:04:21 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Request to remove items from the playlist in SyncPlay group.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The items to remove.</param>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <response code="204">Queue update sent to all group members.</response>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("RemoveFromPlaylist")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlayRemoveFromPlaylist(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] RemoveFromPlaylistRequestDto requestData)
|
2020-09-24 21:04:21 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new RemoveFromPlaylistGroupRequest(requestData.PlaylistItemIds);
|
2020-09-24 21:04:21 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Request to move an item in the playlist in SyncPlay group.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The new position for the item.</param>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <response code="204">Queue update sent to all group members.</response>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("MovePlaylistItem")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlayMovePlaylistItem(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] MovePlaylistItemRequestDto requestData)
|
2020-09-24 21:04:21 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new MovePlaylistItemGroupRequest(requestData.PlaylistItemId, requestData.NewIndex);
|
2020-09-24 21:04:21 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Request to queue items to the playlist of a SyncPlay group.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The items to add.</param>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <response code="204">Queue update sent to all group members.</response>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("Queue")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlayQueue(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] QueueRequestDto requestData)
|
2020-07-15 14:15:17 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new QueueGroupRequest(requestData.ItemIds, requestData.Mode);
|
2020-07-15 14:15:17 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Request unpause in SyncPlay group.
|
|
|
|
/// </summary>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <response code="204">Unpause update sent to all group members.</response>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("Unpause")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlayUnpause()
|
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
|
|
|
var syncPlayRequest = new UnpauseGroupRequest();
|
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
2020-07-15 14:15:17 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Request pause in SyncPlay group.
|
|
|
|
/// </summary>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <response code="204">Pause update sent to all group members.</response>
|
2020-07-15 14:15:17 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
2020-07-22 14:49:52 +00:00
|
|
|
[HttpPost("Pause")]
|
2020-07-22 08:20:51 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-08-03 20:38:51 +00:00
|
|
|
public ActionResult SyncPlayPause()
|
2020-07-15 14:15:17 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-09-24 21:04:21 +00:00
|
|
|
var syncPlayRequest = new PauseGroupRequest();
|
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Request stop in SyncPlay group.
|
|
|
|
/// </summary>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <response code="204">Stop update sent to all group members.</response>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("Stop")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlayStop()
|
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
|
|
|
var syncPlayRequest = new StopGroupRequest();
|
2020-07-15 14:15:17 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Request seek in SyncPlay group.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The new playback position.</param>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <response code="204">Seek update sent to all group members.</response>
|
2020-07-15 14:15:17 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
2020-07-22 14:49:52 +00:00
|
|
|
[HttpPost("Seek")]
|
2020-07-22 08:20:51 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlaySeek(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] SeekRequestDto requestData)
|
2020-07-15 14:15:17 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new SeekGroupRequest(requestData.PositionTicks);
|
2020-07-15 14:15:17 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// Notify SyncPlay group that member is buffering.
|
2020-07-15 14:15:17 +00:00
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The player status.</param>
|
|
|
|
/// <response code="204">Group state update sent to all group members.</response>
|
2020-07-15 14:15:17 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
2020-07-22 14:49:52 +00:00
|
|
|
[HttpPost("Buffering")]
|
2020-07-22 08:20:51 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlayBuffering(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] BufferRequestDto requestData)
|
2020-07-15 14:15:17 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new BufferGroupRequest(
|
|
|
|
requestData.When,
|
|
|
|
requestData.PositionTicks,
|
|
|
|
requestData.IsPlaying,
|
|
|
|
requestData.PlaylistItemId);
|
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
2020-09-24 21:04:21 +00:00
|
|
|
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Notify SyncPlay group that member is ready for playback.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="requestData">The player status.</param>
|
|
|
|
/// <response code="204">Group state update sent to all group members.</response>
|
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("Ready")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-11-28 13:19:24 +00:00
|
|
|
public ActionResult SyncPlayReady(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] ReadyRequestDto requestData)
|
2020-11-28 13:19:24 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
|
|
|
var syncPlayRequest = new ReadyGroupRequest(
|
|
|
|
requestData.When,
|
|
|
|
requestData.PositionTicks,
|
|
|
|
requestData.IsPlaying,
|
|
|
|
requestData.PlaylistItemId);
|
2020-09-24 21:04:21 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Request SyncPlay group to ignore member during group-wait.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The settings to set.</param>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <response code="204">Member state updated.</response>
|
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("SetIgnoreWait")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlaySetIgnoreWait(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] IgnoreWaitRequestDto requestData)
|
2020-09-24 21:04:21 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new IgnoreWaitGroupRequest(requestData.IgnoreWait);
|
2020-09-24 21:04:21 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// Request next item in SyncPlay group.
|
2020-09-24 21:04:21 +00:00
|
|
|
/// </summary>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <param name="requestData">The current item information.</param>
|
|
|
|
/// <response code="204">Next item update sent to all group members.</response>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
2020-12-03 14:41:34 +00:00
|
|
|
[HttpPost("NextItem")]
|
2020-09-24 21:04:21 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-12-03 14:41:34 +00:00
|
|
|
public ActionResult SyncPlayNextItem(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] NextItemRequestDto requestData)
|
2020-09-24 21:04:21 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-12-03 14:41:34 +00:00
|
|
|
var syncPlayRequest = new NextItemGroupRequest(requestData.PlaylistItemId);
|
2020-09-24 21:04:21 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// Request previous item in SyncPlay group.
|
2020-09-24 21:04:21 +00:00
|
|
|
/// </summary>
|
2020-12-03 14:41:34 +00:00
|
|
|
/// <param name="requestData">The current item information.</param>
|
|
|
|
/// <response code="204">Previous item update sent to all group members.</response>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
2020-12-03 14:41:34 +00:00
|
|
|
[HttpPost("PreviousItem")]
|
2020-09-24 21:04:21 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-12-03 14:41:34 +00:00
|
|
|
public ActionResult SyncPlayPreviousItem(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] PreviousItemRequestDto requestData)
|
2020-09-24 21:04:21 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-12-03 14:41:34 +00:00
|
|
|
var syncPlayRequest = new PreviousItemGroupRequest(requestData.PlaylistItemId);
|
2020-09-24 21:04:21 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Request to set repeat mode in SyncPlay group.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The new repeat mode.</param>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <response code="204">Play queue update sent to all group members.</response>
|
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("SetRepeatMode")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlaySetRepeatMode(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] SetRepeatModeRequestDto requestData)
|
2020-09-24 21:04:21 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new SetRepeatModeGroupRequest(requestData.Mode);
|
2020-09-24 21:04:21 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Request to set shuffle mode in SyncPlay group.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The new shuffle mode.</param>
|
2020-09-24 21:04:21 +00:00
|
|
|
/// <response code="204">Play queue update sent to all group members.</response>
|
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
|
|
|
[HttpPost("SetShuffleMode")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-12-07 09:33:15 +00:00
|
|
|
[Authorize(Policy = Policies.SyncPlayIsInGroup)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlaySetShuffleMode(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] SetShuffleModeRequestDto requestData)
|
2020-09-24 21:04:21 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new SetShuffleModeGroupRequest(requestData.Mode);
|
2020-07-15 14:15:17 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Update session ping.
|
|
|
|
/// </summary>
|
2020-11-28 13:19:24 +00:00
|
|
|
/// <param name="requestData">The new ping.</param>
|
2020-07-22 08:20:51 +00:00
|
|
|
/// <response code="204">Ping updated.</response>
|
2020-07-15 14:15:17 +00:00
|
|
|
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
2020-07-22 14:53:56 +00:00
|
|
|
[HttpPost("Ping")]
|
2020-07-22 08:20:51 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-09-24 21:04:21 +00:00
|
|
|
public ActionResult SyncPlayPing(
|
2020-12-03 18:01:57 +00:00
|
|
|
[FromBody, Required] PingRequestDto requestData)
|
2020-07-15 14:15:17 +00:00
|
|
|
{
|
|
|
|
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
|
2020-11-28 13:19:24 +00:00
|
|
|
var syncPlayRequest = new PingGroupRequest(requestData.Ping);
|
2020-07-15 14:15:17 +00:00
|
|
|
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|