diff --git a/Jellyfin.Api/Controllers/SessionController.cs b/Jellyfin.Api/Controllers/SessionController.cs index 60de66ab00..86d5f971d3 100644 --- a/Jellyfin.Api/Controllers/SessionController.cs +++ b/Jellyfin.Api/Controllers/SessionController.cs @@ -55,6 +55,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")] @@ -63,7 +64,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; @@ -118,6 +120,13 @@ public class SessionController : BaseJellyfinApiController result = result.Where(i => i.LastActivityDate >= minActiveDate); } + if (nowPlaying.HasValue) + { + result = nowPlaying.Value + ? result.Where(i => i.NowPlayingItem != null) + : 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 ab68884f9a..61fafc0c3d 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,18 @@ public class SessionControllerTests : IClassFixture using var response = await client.GetAsync($"Sessions?controllableByUserId={Guid.NewGuid()}"); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } + + [Theory] + [InlineData("?nowPlaying=false")] + [InlineData("?nowPlaying=true")] + [InlineData("")] + public async Task GetSessions_NowPlaying_Ok(string querystring) + { + var client = _factory.CreateClient(); + client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false)); + + using var response = await client.GetAsync($"Sessions{querystring}").ConfigureAwait(false); + + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } }