aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Api/Controllers')
-rw-r--r--Jellyfin.Api/Controllers/ConfigurationController.cs5
-rw-r--r--Jellyfin.Api/Controllers/PluginsController.cs5
-rw-r--r--Jellyfin.Api/Controllers/SyncPlayController.cs205
-rw-r--r--Jellyfin.Api/Controllers/TimeSyncController.cs39
4 files changed, 252 insertions, 2 deletions
diff --git a/Jellyfin.Api/Controllers/ConfigurationController.cs b/Jellyfin.Api/Controllers/ConfigurationController.cs
index 13933cb33..7d262ed59 100644
--- a/Jellyfin.Api/Controllers/ConfigurationController.cs
+++ b/Jellyfin.Api/Controllers/ConfigurationController.cs
@@ -2,6 +2,7 @@ using System.Text.Json;
using System.Threading.Tasks;
using Jellyfin.Api.Constants;
using Jellyfin.Api.Models.ConfigurationDtos;
+using MediaBrowser.Common.Json;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Configuration;
@@ -22,6 +23,8 @@ namespace Jellyfin.Api.Controllers
private readonly IServerConfigurationManager _configurationManager;
private readonly IMediaEncoder _mediaEncoder;
+ private readonly JsonSerializerOptions _serializerOptions = JsonDefaults.GetOptions();
+
/// <summary>
/// Initializes a new instance of the <see cref="ConfigurationController"/> class.
/// </summary>
@@ -87,7 +90,7 @@ namespace Jellyfin.Api.Controllers
public async Task<ActionResult> UpdateNamedConfiguration([FromRoute] string? key)
{
var configurationType = _configurationManager.GetConfigurationType(key);
- var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType).ConfigureAwait(false);
+ var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType, _serializerOptions).ConfigureAwait(false);
_configurationManager.SaveConfiguration(key, configuration);
return NoContent();
}
diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs
index 48bb867ac..770d74838 100644
--- a/Jellyfin.Api/Controllers/PluginsController.cs
+++ b/Jellyfin.Api/Controllers/PluginsController.cs
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Jellyfin.Api.Constants;
using Jellyfin.Api.Models.PluginDtos;
using MediaBrowser.Common;
+using MediaBrowser.Common.Json;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Updates;
using MediaBrowser.Model.Plugins;
@@ -25,6 +26,8 @@ namespace Jellyfin.Api.Controllers
private readonly IApplicationHost _appHost;
private readonly IInstallationManager _installationManager;
+ private readonly JsonSerializerOptions _serializerOptions = JsonDefaults.GetOptions();
+
/// <summary>
/// Initializes a new instance of the <see cref="PluginsController"/> class.
/// </summary>
@@ -117,7 +120,7 @@ namespace Jellyfin.Api.Controllers
return NotFound();
}
- var configuration = (BasePluginConfiguration)await JsonSerializer.DeserializeAsync(Request.Body, plugin.ConfigurationType)
+ var configuration = (BasePluginConfiguration)await JsonSerializer.DeserializeAsync(Request.Body, plugin.ConfigurationType, _serializerOptions)
.ConfigureAwait(false);
plugin.UpdateConfiguration(configuration);
diff --git a/Jellyfin.Api/Controllers/SyncPlayController.cs b/Jellyfin.Api/Controllers/SyncPlayController.cs
new file mode 100644
index 000000000..55ed42227
--- /dev/null
+++ b/Jellyfin.Api/Controllers/SyncPlayController.cs
@@ -0,0 +1,205 @@
+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.Http;
+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>
+ /// <response code="204">New group created.</response>
+ /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
+ [HttpPost("New")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ 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>
+ /// <response code="204">Group join successful.</response>
+ /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
+ [HttpPost("Join")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ 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>
+ /// <response code="204">Group leave successful.</response>
+ /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
+ [HttpPost("Leave")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ 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>
+ /// <response code="200">Groups returned.</response>
+ /// <returns>An <see cref="IEnumerable{GrouüInfoView}"/> containing the available SyncPlay groups.</returns>
+ [HttpGet("List")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ 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>
+ /// <response code="204">Play request sent to all group members.</response>
+ /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
+ [HttpPost("Play")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ 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>
+ /// <response code="204">Pause request sent to all group members.</response>
+ /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
+ [HttpPost("Pause")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ 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>
+ /// <response code="204">Seek request sent to all group members.</response>
+ /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
+ [HttpPost("Seek")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ 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>
+ /// <response code="204">Buffering request sent to all group members.</response>
+ /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
+ [HttpPost("Buffering")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ 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.Ready : PlaybackRequestType.Buffer,
+ When = when,
+ PositionTicks = positionTicks
+ };
+ _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
+ return NoContent();
+ }
+
+ /// <summary>
+ /// Update session ping.
+ /// </summary>
+ /// <param name="ping">The ping.</param>
+ /// <response code="204">Ping updated.</response>
+ /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
+ [HttpPost("Ping")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ public ActionResult Ping([FromQuery] double ping)
+ {
+ var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
+ var syncPlayRequest = new PlaybackRequest()
+ {
+ Type = PlaybackRequestType.Ping,
+ Ping = Convert.ToInt64(ping)
+ };
+ _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
+ return NoContent();
+ }
+ }
+}
diff --git a/Jellyfin.Api/Controllers/TimeSyncController.cs b/Jellyfin.Api/Controllers/TimeSyncController.cs
new file mode 100644
index 000000000..57a720b26
--- /dev/null
+++ b/Jellyfin.Api/Controllers/TimeSyncController.cs
@@ -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;
+ }
+ }
+}