mirror of https://github.com/jellyfin/jellyfin.git
feat: SessionController GetSessions() , added nowPlaying` to filter only sessions that have an item currently playing
This commit is contained in:
parent
08aac57529
commit
99bcb6f1b8
|
@ -53,6 +53,7 @@ public class SessionController : BaseJellyfinApiController
|
|||
/// <param name="controllableByUserId">Filter by sessions that a given user is allowed to remote control.</param>
|
||||
/// <param name="deviceId">Filter by device Id.</param>
|
||||
/// <param name="activeWithinSeconds">Optional. Filter by sessions that were active in the last n seconds.</param>
|
||||
/// <param name="nowPlaying">Optional. Filter by sessions that are currently playing content.</param>
|
||||
/// <response code="200">List of sessions returned.</response>
|
||||
/// <returns>An <see cref="IEnumerable{SessionInfo}"/> with the available sessions.</returns>
|
||||
[HttpGet("Sessions")]
|
||||
|
@ -61,7 +62,8 @@ public class SessionController : BaseJellyfinApiController
|
|||
public ActionResult<IEnumerable<SessionInfo>> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<JellyfinApplicationFactory>
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue