Move query parameters to request body in SyncPlay

This commit is contained in:
Ionut Andrei Oanca 2020-11-28 14:19:24 +01:00
parent ba78ad5424
commit c60714e365
26 changed files with 475 additions and 136 deletions

View File

@ -13,6 +13,7 @@ using MediaBrowser.Controller.SyncPlay;
using MediaBrowser.Controller.SyncPlay.GroupStates; using MediaBrowser.Controller.SyncPlay.GroupStates;
using MediaBrowser.Controller.SyncPlay.Queue; using MediaBrowser.Controller.SyncPlay.Queue;
using MediaBrowser.Model.SyncPlay; using MediaBrowser.Model.SyncPlay;
using MediaBrowser.Model.SyncPlay.RequestBodies;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.SyncPlay namespace Emby.Server.Implementations.SyncPlay
@ -256,7 +257,7 @@ namespace Emby.Server.Implementations.SyncPlay
public bool IsGroupEmpty() => _participants.Count == 0; public bool IsGroupEmpty() => _participants.Count == 0;
/// <inheritdoc /> /// <inheritdoc />
public void CreateGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken) public void CreateGroup(SessionInfo session, NewGroupRequestBody request, CancellationToken cancellationToken)
{ {
GroupName = request.GroupName; GroupName = request.GroupName;
AddSession(session); AddSession(session);
@ -291,7 +292,7 @@ namespace Emby.Server.Implementations.SyncPlay
} }
/// <inheritdoc /> /// <inheritdoc />
public void SessionJoin(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken) public void SessionJoin(SessionInfo session, JoinGroupRequestBody request, CancellationToken cancellationToken)
{ {
AddSession(session); AddSession(session);
@ -307,7 +308,7 @@ namespace Emby.Server.Implementations.SyncPlay
} }
/// <inheritdoc /> /// <inheritdoc />
public void SessionRestore(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken) public void SessionRestore(SessionInfo session, JoinGroupRequestBody request, CancellationToken cancellationToken)
{ {
var updateSession = NewSyncPlayGroupUpdate(GroupUpdateType.GroupJoined, GetInfo()); var updateSession = NewSyncPlayGroupUpdate(GroupUpdateType.GroupJoined, GetInfo());
SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken); SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken);

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using Jellyfin.Data.Enums; using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.SyncPlay; using MediaBrowser.Controller.SyncPlay;
using MediaBrowser.Model.SyncPlay; using MediaBrowser.Model.SyncPlay;
using MediaBrowser.Model.SyncPlay.RequestBodies;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.SyncPlay namespace Emby.Server.Implementations.SyncPlay
@ -94,7 +94,7 @@ namespace Emby.Server.Implementations.SyncPlay
} }
/// <inheritdoc /> /// <inheritdoc />
public void NewGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken) public void NewGroup(SessionInfo session, NewGroupRequestBody request, CancellationToken cancellationToken)
{ {
// TODO: create abstract class for GroupRequests to avoid explicit request type here. // TODO: create abstract class for GroupRequests to avoid explicit request type here.
if (!IsRequestValid(session, GroupRequestType.NewGroup, request)) if (!IsRequestValid(session, GroupRequestType.NewGroup, request))
@ -124,7 +124,7 @@ namespace Emby.Server.Implementations.SyncPlay
} }
/// <inheritdoc /> /// <inheritdoc />
public void JoinGroup(SessionInfo session, Guid groupId, JoinGroupRequest request, CancellationToken cancellationToken) public void JoinGroup(SessionInfo session, Guid groupId, JoinGroupRequestBody request, CancellationToken cancellationToken)
{ {
// TODO: create abstract class for GroupRequests to avoid explicit request type here. // TODO: create abstract class for GroupRequests to avoid explicit request type here.
if (!IsRequestValid(session, GroupRequestType.JoinGroup, request)) if (!IsRequestValid(session, GroupRequestType.JoinGroup, request))
@ -304,7 +304,10 @@ namespace Emby.Server.Implementations.SyncPlay
return; return;
} }
var request = new JoinGroupRequest(groupId); var request = new JoinGroupRequestBody()
{
GroupId = groupId
};
JoinGroup(session, groupId, request, CancellationToken.None); JoinGroup(session, groupId, request, CancellationToken.None);
} }

View File

@ -9,6 +9,7 @@ using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.SyncPlay; using MediaBrowser.Controller.SyncPlay;
using MediaBrowser.Controller.SyncPlay.PlaybackRequests; using MediaBrowser.Controller.SyncPlay.PlaybackRequests;
using MediaBrowser.Model.SyncPlay; using MediaBrowser.Model.SyncPlay;
using MediaBrowser.Model.SyncPlay.RequestBodies;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -44,34 +45,32 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Create a new SyncPlay group. /// Create a new SyncPlay group.
/// </summary> /// </summary>
/// <param name="groupName">The name of the new group.</param> /// <param name="requestData">The settings of the new group.</param>
/// <response code="204">New group created.</response> /// <response code="204">New group created.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("New")] [HttpPost("New")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayCreateGroup( public ActionResult SyncPlayCreateGroup(
[FromQuery, Required] string groupName) [FromBody, Required] NewGroupRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var newGroupRequest = new NewGroupRequest(groupName); _syncPlayManager.NewGroup(currentSession, requestData, CancellationToken.None);
_syncPlayManager.NewGroup(currentSession, newGroupRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
/// <summary> /// <summary>
/// Join an existing SyncPlay group. /// Join an existing SyncPlay group.
/// </summary> /// </summary>
/// <param name="groupId">The sync play group id.</param> /// <param name="requestData">The group to join.</param>
/// <response code="204">Group join successful.</response> /// <response code="204">Group join successful.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("Join")] [HttpPost("Join")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayJoinGroup( public ActionResult SyncPlayJoinGroup(
[FromQuery, Required] Guid groupId) [FromBody, Required] JoinGroupRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var joinRequest = new JoinGroupRequest(groupId); _syncPlayManager.JoinGroup(currentSession, requestData.GroupId, requestData, CancellationToken.None);
_syncPlayManager.JoinGroup(currentSession, groupId, joinRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -105,20 +104,19 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request play in SyncPlay group. /// Request play in SyncPlay group.
/// </summary> /// </summary>
/// <param name="playingQueue">The playing queue. Item ids in the playing queue, comma delimited.</param> /// <param name="requestData">The new playlist to play in the group.</param>
/// <param name="playingItemPosition">The playing item position from the queue.</param>
/// <param name="startPositionTicks">The start position ticks.</param>
/// <response code="204">Play request sent to all group members.</response> /// <response code="204">Play request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("Play")] [HttpPost("Play")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayPlay( public ActionResult SyncPlayPlay(
[FromQuery, Required] Guid[] playingQueue, [FromBody, Required] PlayRequestBody requestData)
[FromQuery, Required] int playingItemPosition,
[FromQuery, Required] long startPositionTicks)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new PlayGroupRequest(playingQueue, playingItemPosition, startPositionTicks); var syncPlayRequest = new PlayGroupRequest(
requestData.PlayingQueue,
requestData.PlayingItemPosition,
requestData.StartPositionTicks);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -126,16 +124,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request to change playlist item in SyncPlay group. /// Request to change playlist item in SyncPlay group.
/// </summary> /// </summary>
/// <param name="playlistItemId">The playlist id of the item.</param> /// <param name="requestData">The new item to play.</param>
/// <response code="204">Queue update request sent to all group members.</response> /// <response code="204">Queue update request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("SetPlaylistItem")] [HttpPost("SetPlaylistItem")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlaySetPlaylistItem( public ActionResult SyncPlaySetPlaylistItem(
[FromQuery, Required] string playlistItemId) [FromBody, Required] SetPlaylistItemRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new SetPlaylistItemGroupRequest(playlistItemId); var syncPlayRequest = new SetPlaylistItemGroupRequest(requestData.PlaylistItemId);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -143,16 +141,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request to remove items from the playlist in SyncPlay group. /// Request to remove items from the playlist in SyncPlay group.
/// </summary> /// </summary>
/// <param name="playlistItemIds">The playlist ids of the items to remove.</param> /// <param name="requestData">The items to remove.</param>
/// <response code="204">Queue update request sent to all group members.</response> /// <response code="204">Queue update request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("RemoveFromPlaylist")] [HttpPost("RemoveFromPlaylist")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayRemoveFromPlaylist( public ActionResult SyncPlayRemoveFromPlaylist(
[FromQuery, Required] string[] playlistItemIds) [FromBody, Required] RemoveFromPlaylistRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new RemoveFromPlaylistGroupRequest(playlistItemIds); var syncPlayRequest = new RemoveFromPlaylistGroupRequest(requestData.PlaylistItemIds);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -160,18 +158,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request to move an item in the playlist in SyncPlay group. /// Request to move an item in the playlist in SyncPlay group.
/// </summary> /// </summary>
/// <param name="playlistItemId">The playlist id of the item to move.</param> /// <param name="requestData">The new position for the item.</param>
/// <param name="newIndex">The new position.</param>
/// <response code="204">Queue update request sent to all group members.</response> /// <response code="204">Queue update request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("MovePlaylistItem")] [HttpPost("MovePlaylistItem")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayMovePlaylistItem( public ActionResult SyncPlayMovePlaylistItem(
[FromQuery, Required] string playlistItemId, [FromBody, Required] MovePlaylistItemRequestBody requestData)
[FromQuery, Required] int newIndex)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new MovePlaylistItemGroupRequest(playlistItemId, newIndex); var syncPlayRequest = new MovePlaylistItemGroupRequest(requestData.PlaylistItemId, requestData.NewIndex);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -179,18 +175,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request to queue items to the playlist of a SyncPlay group. /// Request to queue items to the playlist of a SyncPlay group.
/// </summary> /// </summary>
/// <param name="itemIds">The items to add.</param> /// <param name="requestData">The items to add.</param>
/// <param name="mode">The mode in which to enqueue the items.</param>
/// <response code="204">Queue update request sent to all group members.</response> /// <response code="204">Queue update request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("Queue")] [HttpPost("Queue")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayQueue( public ActionResult SyncPlayQueue(
[FromQuery, Required] Guid[] itemIds, [FromBody, Required] QueueRequestBody requestData)
[FromQuery, Required] GroupQueueMode mode)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new QueueGroupRequest(itemIds, mode); var syncPlayRequest = new QueueGroupRequest(requestData.ItemIds, requestData.Mode);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -243,50 +237,58 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request seek in SyncPlay group. /// Request seek in SyncPlay group.
/// </summary> /// </summary>
/// <param name="positionTicks">The playback position in ticks.</param> /// <param name="requestData">The new playback position.</param>
/// <response code="204">Seek request sent to all group members.</response> /// <response code="204">Seek request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("Seek")] [HttpPost("Seek")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlaySeek( public ActionResult SyncPlaySeek(
[FromQuery, Required] long positionTicks) [FromBody, Required] SeekRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new SeekGroupRequest(positionTicks); var syncPlayRequest = new SeekGroupRequest(requestData.PositionTicks);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
/// <summary> /// <summary>
/// Request group wait in SyncPlay group while buffering. /// Notify SyncPlay group that member is buffering.
/// </summary> /// </summary>
/// <param name="when">When the request has been made by the client.</param> /// <param name="requestData">The player status.</param>
/// <param name="positionTicks">The playback position in ticks.</param> /// <response code="204">Group state update sent to all group members.</response>
/// <param name="isPlaying">Whether the client's playback is playing or not.</param>
/// <param name="playlistItemId">The playlist item id.</param>
/// <param name="bufferingDone">Whether the buffering is done.</param>
/// <response code="204">Buffering request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("Buffering")] [HttpPost("Buffering")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayBuffering( public ActionResult SyncPlayBuffering(
[FromQuery, Required] DateTime when, [FromBody, Required] BufferRequestBody requestData)
[FromQuery, Required] long positionTicks,
[FromQuery, Required] bool isPlaying,
[FromQuery, Required] string playlistItemId,
[FromQuery, Required] bool bufferingDone)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
IGroupPlaybackRequest syncPlayRequest; var syncPlayRequest = new BufferGroupRequest(
if (!bufferingDone) requestData.When,
{ requestData.PositionTicks,
syncPlayRequest = new BufferGroupRequest(when, positionTicks, isPlaying, playlistItemId); requestData.IsPlaying,
} requestData.PlaylistItemId);
else _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
{ return NoContent();
syncPlayRequest = new ReadyGroupRequest(when, positionTicks, isPlaying, playlistItemId); }
}
/// <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)]
public ActionResult SyncPlayReady(
[FromBody, Required] ReadyRequestBody requestData)
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new ReadyGroupRequest(
requestData.When,
requestData.PositionTicks,
requestData.IsPlaying,
requestData.PlaylistItemId);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -294,16 +296,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request SyncPlay group to ignore member during group-wait. /// Request SyncPlay group to ignore member during group-wait.
/// </summary> /// </summary>
/// <param name="ignoreWait">Whether to ignore the member.</param> /// <param name="requestData">The settings to set.</param>
/// <response code="204">Member state updated.</response> /// <response code="204">Member state updated.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("SetIgnoreWait")] [HttpPost("SetIgnoreWait")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlaySetIgnoreWait( public ActionResult SyncPlaySetIgnoreWait(
[FromQuery, Required] bool ignoreWait) [FromBody, Required] IgnoreWaitRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new IgnoreWaitGroupRequest(ignoreWait); var syncPlayRequest = new IgnoreWaitGroupRequest(requestData.IgnoreWait);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -311,16 +313,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request next track in SyncPlay group. /// Request next track in SyncPlay group.
/// </summary> /// </summary>
/// <param name="playlistItemId">The playing item id.</param> /// <param name="requestData">The current track information.</param>
/// <response code="204">Next track request sent to all group members.</response> /// <response code="204">Next track request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("NextTrack")] [HttpPost("NextTrack")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayNextTrack( public ActionResult SyncPlayNextTrack(
[FromQuery, Required] string playlistItemId) [FromBody, Required] NextTrackRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new NextTrackGroupRequest(playlistItemId); var syncPlayRequest = new NextTrackGroupRequest(requestData.PlaylistItemId);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -328,16 +330,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request previous track in SyncPlay group. /// Request previous track in SyncPlay group.
/// </summary> /// </summary>
/// <param name="playlistItemId">The playing item id.</param> /// <param name="requestData">The current track information.</param>
/// <response code="204">Previous track request sent to all group members.</response> /// <response code="204">Previous track request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("PreviousTrack")] [HttpPost("PreviousTrack")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayPreviousTrack( public ActionResult SyncPlayPreviousTrack(
[FromQuery, Required] string playlistItemId) [FromBody, Required] PreviousTrackRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new PreviousTrackGroupRequest(playlistItemId); var syncPlayRequest = new PreviousTrackGroupRequest(requestData.PlaylistItemId);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -345,16 +347,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request to set repeat mode in SyncPlay group. /// Request to set repeat mode in SyncPlay group.
/// </summary> /// </summary>
/// <param name="mode">The repeat mode.</param> /// <param name="requestData">The new repeat mode.</param>
/// <response code="204">Play queue update sent to all group members.</response> /// <response code="204">Play queue update sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("SetRepeatMode")] [HttpPost("SetRepeatMode")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlaySetRepeatMode( public ActionResult SyncPlaySetRepeatMode(
[FromQuery, Required] GroupRepeatMode mode) [FromBody, Required] SetRepeatModeRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new SetRepeatModeGroupRequest(mode); var syncPlayRequest = new SetRepeatModeGroupRequest(requestData.Mode);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -362,16 +364,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request to set shuffle mode in SyncPlay group. /// Request to set shuffle mode in SyncPlay group.
/// </summary> /// </summary>
/// <param name="mode">The shuffle mode.</param> /// <param name="requestData">The new shuffle mode.</param>
/// <response code="204">Play queue update sent to all group members.</response> /// <response code="204">Play queue update sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("SetShuffleMode")] [HttpPost("SetShuffleMode")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlaySetShuffleMode( public ActionResult SyncPlaySetShuffleMode(
[FromQuery, Required] GroupShuffleMode mode) [FromBody, Required] SetShuffleModeRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new SetShuffleModeGroupRequest(mode); var syncPlayRequest = new SetShuffleModeGroupRequest(requestData.Mode);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -379,16 +381,16 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Update session ping. /// Update session ping.
/// </summary> /// </summary>
/// <param name="ping">The ping.</param> /// <param name="requestData">The new ping.</param>
/// <response code="204">Ping updated.</response> /// <response code="204">Ping updated.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("Ping")] [HttpPost("Ping")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayPing( public ActionResult SyncPlayPing(
[FromQuery, Required] double ping) [FromBody, Required] PingRequestBody requestData)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new PingGroupRequest(Convert.ToInt64(ping)); var syncPlayRequest = new PingGroupRequest(requestData.Ping);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }

View File

@ -4,6 +4,7 @@ using Jellyfin.Data.Entities;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.SyncPlay.Queue; using MediaBrowser.Controller.SyncPlay.Queue;
using MediaBrowser.Model.SyncPlay; using MediaBrowser.Model.SyncPlay;
using MediaBrowser.Model.SyncPlay.RequestBodies;
namespace MediaBrowser.Controller.SyncPlay namespace MediaBrowser.Controller.SyncPlay
{ {
@ -36,7 +37,7 @@ namespace MediaBrowser.Controller.SyncPlay
/// <param name="session">The session.</param> /// <param name="session">The session.</param>
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
void CreateGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken); void CreateGroup(SessionInfo session, NewGroupRequestBody request, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Adds the session to the group. /// Adds the session to the group.
@ -44,7 +45,7 @@ namespace MediaBrowser.Controller.SyncPlay
/// <param name="session">The session.</param> /// <param name="session">The session.</param>
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
void SessionJoin(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken); void SessionJoin(SessionInfo session, JoinGroupRequestBody request, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Restores the state of a session that already joined the group. /// Restores the state of a session that already joined the group.
@ -52,7 +53,7 @@ namespace MediaBrowser.Controller.SyncPlay
/// <param name="session">The session.</param> /// <param name="session">The session.</param>
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
void SessionRestore(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken); void SessionRestore(SessionInfo session, JoinGroupRequestBody request, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Removes the session from the group. /// Removes the session from the group.

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Model.SyncPlay; using MediaBrowser.Model.SyncPlay;
using MediaBrowser.Model.SyncPlay.RequestBodies;
namespace MediaBrowser.Controller.SyncPlay namespace MediaBrowser.Controller.SyncPlay
{ {
@ -17,7 +18,7 @@ namespace MediaBrowser.Controller.SyncPlay
/// <param name="session">The session that's creating the group.</param> /// <param name="session">The session that's creating the group.</param>
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
void NewGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken); void NewGroup(SessionInfo session, NewGroupRequestBody request, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Adds the session to a group. /// Adds the session to a group.
@ -26,7 +27,7 @@ namespace MediaBrowser.Controller.SyncPlay
/// <param name="groupId">The group identifier.</param> /// <param name="groupId">The group identifier.</param>
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
void JoinGroup(SessionInfo session, Guid groupId, JoinGroupRequest request, CancellationToken cancellationToken); void JoinGroup(SessionInfo session, Guid groupId, JoinGroupRequestBody request, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Removes the session from a group. /// Removes the session from a group.

View File

@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.SyncPlay.PlaybackRequests
/// <param name="playingQueue">The playing queue.</param> /// <param name="playingQueue">The playing queue.</param>
/// <param name="playingItemPosition">The playing item position.</param> /// <param name="playingItemPosition">The playing item position.</param>
/// <param name="startPositionTicks">The start position ticks.</param> /// <param name="startPositionTicks">The start position ticks.</param>
public PlayGroupRequest(Guid[] playingQueue, int playingItemPosition, long startPositionTicks) public PlayGroupRequest(IReadOnlyList<Guid> playingQueue, int playingItemPosition, long startPositionTicks)
{ {
PlayingQueue = playingQueue ?? Array.Empty<Guid>(); PlayingQueue = playingQueue ?? Array.Empty<Guid>();
PlayingItemPosition = playingItemPosition; PlayingItemPosition = playingItemPosition;

View File

@ -16,7 +16,7 @@ namespace MediaBrowser.Controller.SyncPlay.PlaybackRequests
/// </summary> /// </summary>
/// <param name="items">The items to add to the queue.</param> /// <param name="items">The items to add to the queue.</param>
/// <param name="mode">The enqueue mode.</param> /// <param name="mode">The enqueue mode.</param>
public QueueGroupRequest(Guid[] items, GroupQueueMode mode) public QueueGroupRequest(IReadOnlyList<Guid> items, GroupQueueMode mode)
{ {
ItemIds = items ?? Array.Empty<Guid>(); ItemIds = items ?? Array.Empty<Guid>();
Mode = mode; Mode = mode;

View File

@ -15,7 +15,7 @@ namespace MediaBrowser.Controller.SyncPlay.PlaybackRequests
/// Initializes a new instance of the <see cref="RemoveFromPlaylistGroupRequest"/> class. /// Initializes a new instance of the <see cref="RemoveFromPlaylistGroupRequest"/> class.
/// </summary> /// </summary>
/// <param name="items">The playlist ids of the items to remove.</param> /// <param name="items">The playlist ids of the items to remove.</param>
public RemoveFromPlaylistGroupRequest(string[] items) public RemoveFromPlaylistGroupRequest(IReadOnlyList<string> items)
{ {
PlaylistItemIds = items ?? Array.Empty<string>(); PlaylistItemIds = items ?? Array.Empty<string>();
} }

View File

@ -1,25 +0,0 @@
using System;
namespace MediaBrowser.Model.SyncPlay
{
/// <summary>
/// Class JoinGroupRequest.
/// </summary>
public class JoinGroupRequest
{
/// <summary>
/// Initializes a new instance of the <see cref="JoinGroupRequest"/> class.
/// </summary>
/// <param name="groupId">The identifier of the group to join.</param>
public JoinGroupRequest(Guid groupId)
{
GroupId = groupId;
}
/// <summary>
/// Gets the group identifier.
/// </summary>
/// <value>The identifier of the group to join.</value>
public Guid GroupId { get; }
}
}

View File

@ -1,23 +0,0 @@
namespace MediaBrowser.Model.SyncPlay
{
/// <summary>
/// Class NewGroupRequest.
/// </summary>
public class NewGroupRequest
{
/// <summary>
/// Initializes a new instance of the <see cref="NewGroupRequest"/> class.
/// </summary>
/// <param name="groupName">The name of the new group.</param>
public NewGroupRequest(string groupName)
{
GroupName = groupName;
}
/// <summary>
/// Gets the group name.
/// </summary>
/// <value>The name of the new group.</value>
public string GroupName { get; }
}
}

View File

@ -0,0 +1,42 @@
using System;
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class BufferRequestBody.
/// </summary>
public class BufferRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="BufferRequestBody"/> class.
/// </summary>
public BufferRequestBody()
{
PlaylistItemId = string.Empty;
}
/// <summary>
/// Gets or sets when the request has been made by the client.
/// </summary>
/// <value>The date of the request.</value>
public DateTime When { get; set; }
/// <summary>
/// Gets or sets the position ticks.
/// </summary>
/// <value>The position ticks.</value>
public long PositionTicks { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the client playback is unpaused.
/// </summary>
/// <value>The client playback status.</value>
public bool IsPlaying { get; set; }
/// <summary>
/// Gets or sets the playlist item identifier of the playing item.
/// </summary>
/// <value>The playlist item identifier.</value>
public string PlaylistItemId { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class IgnoreWaitRequestBody.
/// </summary>
public class IgnoreWaitRequestBody
{
/// <summary>
/// Gets or sets a value indicating whether the client should be ignored.
/// </summary>
/// <value>The client group-wait status.</value>
public bool IgnoreWait { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class JoinGroupRequestBody.
/// </summary>
public class JoinGroupRequestBody
{
/// <summary>
/// Gets or sets the group identifier.
/// </summary>
/// <value>The identifier of the group to join.</value>
public Guid GroupId { get; set; }
}
}

View File

@ -0,0 +1,28 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class MovePlaylistItemRequestBody.
/// </summary>
public class MovePlaylistItemRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="MovePlaylistItemRequestBody"/> class.
/// </summary>
public MovePlaylistItemRequestBody()
{
PlaylistItemId = string.Empty;
}
/// <summary>
/// Gets or sets the playlist identifier of the item.
/// </summary>
/// <value>The playlist identifier of the item.</value>
public string PlaylistItemId { get; set; }
/// <summary>
/// Gets or sets the new position.
/// </summary>
/// <value>The new position.</value>
public int NewIndex { get; set; }
}
}

View File

@ -0,0 +1,22 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class NewGroupRequestBody.
/// </summary>
public class NewGroupRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="NewGroupRequestBody"/> class.
/// </summary>
public NewGroupRequestBody()
{
GroupName = string.Empty;
}
/// <summary>
/// Gets or sets the group name.
/// </summary>
/// <value>The name of the new group.</value>
public string GroupName { get; set; }
}
}

View File

@ -0,0 +1,22 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class NextTrackRequestBody.
/// </summary>
public class NextTrackRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="NextTrackRequestBody"/> class.
/// </summary>
public NextTrackRequestBody()
{
PlaylistItemId = string.Empty;
}
/// <summary>
/// Gets or sets the playing item identifier.
/// </summary>
/// <value>The playing item identifier.</value>
public string PlaylistItemId { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class PingRequestBody.
/// </summary>
public class PingRequestBody
{
/// <summary>
/// Gets or sets the ping time.
/// </summary>
/// <value>The ping time.</value>
public long Ping { get; set; }
}
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class PlayRequestBody.
/// </summary>
public class PlayRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="PlayRequestBody"/> class.
/// </summary>
public PlayRequestBody()
{
PlayingQueue = Array.Empty<Guid>();
}
/// <summary>
/// Gets or sets the playing queue.
/// </summary>
/// <value>The playing queue.</value>
public IReadOnlyList<Guid> PlayingQueue { get; set; }
/// <summary>
/// Gets or sets the position of the playing item in the queue.
/// </summary>
/// <value>The playing item position.</value>
public int PlayingItemPosition { get; set; }
/// <summary>
/// Gets or sets the start position ticks.
/// </summary>
/// <value>The start position ticks.</value>
public long StartPositionTicks { get; set; }
}
}

View File

@ -0,0 +1,22 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class PreviousTrackRequestBody.
/// </summary>
public class PreviousTrackRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="PreviousTrackRequestBody"/> class.
/// </summary>
public PreviousTrackRequestBody()
{
PlaylistItemId = string.Empty;
}
/// <summary>
/// Gets or sets the playing item identifier.
/// </summary>
/// <value>The playing item identifier.</value>
public string PlaylistItemId { get; set; }
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class QueueRequestBody.
/// </summary>
public class QueueRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="QueueRequestBody"/> class.
/// </summary>
public QueueRequestBody()
{
ItemIds = Array.Empty<Guid>();
}
/// <summary>
/// Gets or sets the items to enqueue.
/// </summary>
/// <value>The items to enqueue.</value>
public IReadOnlyList<Guid> ItemIds { get; set; }
/// <summary>
/// Gets or sets the mode in which to add the new items.
/// </summary>
/// <value>The enqueue mode.</value>
public GroupQueueMode Mode { get; set; }
}
}

View File

@ -0,0 +1,42 @@
using System;
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class ReadyRequest.
/// </summary>
public class ReadyRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="ReadyRequestBody"/> class.
/// </summary>
public ReadyRequestBody()
{
PlaylistItemId = string.Empty;
}
/// <summary>
/// Gets or sets when the request has been made by the client.
/// </summary>
/// <value>The date of the request.</value>
public DateTime When { get; set; }
/// <summary>
/// Gets or sets the position ticks.
/// </summary>
/// <value>The position ticks.</value>
public long PositionTicks { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the client playback is unpaused.
/// </summary>
/// <value>The client playback status.</value>
public bool IsPlaying { get; set; }
/// <summary>
/// Gets or sets the playlist item identifier of the playing item.
/// </summary>
/// <value>The playlist item identifier.</value>
public string PlaylistItemId { get; set; }
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class RemoveFromPlaylistRequestBody.
/// </summary>
public class RemoveFromPlaylistRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="RemoveFromPlaylistRequestBody"/> class.
/// </summary>
public RemoveFromPlaylistRequestBody()
{
PlaylistItemIds = Array.Empty<string>();
}
/// <summary>
/// Gets or sets the playlist identifiers ot the items.
/// </summary>
/// <value>The playlist identifiers ot the items.</value>
public IReadOnlyList<string> PlaylistItemIds { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class SeekRequestBody.
/// </summary>
public class SeekRequestBody
{
/// <summary>
/// Gets or sets the position ticks.
/// </summary>
/// <value>The position ticks.</value>
public long PositionTicks { get; set; }
}
}

View File

@ -0,0 +1,22 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class SetPlaylistItemRequestBody.
/// </summary>
public class SetPlaylistItemRequestBody
{
/// <summary>
/// Initializes a new instance of the <see cref="SetPlaylistItemRequestBody"/> class.
/// </summary>
public SetPlaylistItemRequestBody()
{
PlaylistItemId = string.Empty;
}
/// <summary>
/// Gets or sets the playlist identifier of the playing item.
/// </summary>
/// <value>The playlist identifier of the playing item.</value>
public string PlaylistItemId { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class SetRepeatModeRequestBody.
/// </summary>
public class SetRepeatModeRequestBody
{
/// <summary>
/// Gets or sets the repeat mode.
/// </summary>
/// <value>The repeat mode.</value>
public GroupRepeatMode Mode { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace MediaBrowser.Model.SyncPlay.RequestBodies
{
/// <summary>
/// Class SetShuffleModeRequestBody.
/// </summary>
public class SetShuffleModeRequestBody
{
/// <summary>
/// Gets or sets the shuffle mode.
/// </summary>
/// <value>The shuffle mode.</value>
public GroupShuffleMode Mode { get; set; }
}
}