From 99bcb6f1b835a342735f65199d6043bd55bf76a1 Mon Sep 17 00:00:00 2001 From: Sam Jongenelen Date: Wed, 3 May 2023 10:26:41 +0200 Subject: [PATCH] feat: SessionController GetSessions() , added nowPlaying` to filter only sessions that have an item currently playing --- Jellyfin.Api/Controllers/SessionController.cs | 9 ++++++++- .../Controllers/SessionControllerTests.cs | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Api/Controllers/SessionController.cs b/Jellyfin.Api/Controllers/SessionController.cs index e93456de66..07bbe77ddb 100644 --- a/Jellyfin.Api/Controllers/SessionController.cs +++ b/Jellyfin.Api/Controllers/SessionController.cs @@ -53,6 +53,7 @@ public class SessionController : BaseJellyfinApiController /// Filter by sessions that a given user is allowed to remote control. /// Filter by device Id. /// Optional. Filter by sessions that were active in the last n seconds. + /// Optional. Filter by sessions that are currently playing content. /// List of sessions returned. /// An with the available sessions. [HttpGet("Sessions")] @@ -61,7 +62,8 @@ public class SessionController : BaseJellyfinApiController public ActionResult> GetSessions( [FromQuery] Guid? controllableByUserId, [FromQuery] string? deviceId, - [FromQuery] int? activeWithinSeconds) + [FromQuery] int? activeWithinSeconds, + [FromQuery] bool? nowPlaying) { var result = _sessionManager.Sessions; @@ -110,6 +112,11 @@ public class SessionController : BaseJellyfinApiController }); } + if (nowPlaying.GetValueOrDefault()) + { + result = result.Where(i => i.NowPlayingItem != null); + } + return Ok(result); } diff --git a/tests/Jellyfin.Server.Integration.Tests/Controllers/SessionControllerTests.cs b/tests/Jellyfin.Server.Integration.Tests/Controllers/SessionControllerTests.cs index cb0a829e8e..23275209c2 100644 --- a/tests/Jellyfin.Server.Integration.Tests/Controllers/SessionControllerTests.cs +++ b/tests/Jellyfin.Server.Integration.Tests/Controllers/SessionControllerTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net; using System.Threading.Tasks; using Xunit; @@ -24,4 +24,16 @@ public class SessionControllerTests : IClassFixture using var response = await client.GetAsync($"Session/Sessions?userId={Guid.NewGuid()}").ConfigureAwait(false); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } + + [Fact] + public async Task GetSessions_NowPlaying_Ok() + { + var client = _factory.CreateClient(); + client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false)); + + using var response = await client.GetAsync("Sessions?nowPlaying=true").ConfigureAwait(false); + + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal("[]", await response.Content.ReadAsStringAsync()); + } }