lets try that again

This commit is contained in:
2026-02-02 18:42:12 -05:00
parent 4c55520ce0
commit 045c810abc
2 changed files with 61 additions and 49 deletions

View File

@@ -1789,7 +1789,22 @@ public class JellyfinController : ControllerBase
var (deviceId, client, device, version) = ExtractDeviceInfo(Request.Headers); var (deviceId, client, device, version) = ExtractDeviceInfo(Request.Headers);
if (!string.IsNullOrEmpty(deviceId)) if (!string.IsNullOrEmpty(deviceId))
{ {
await _sessionManager.EnsureSessionAsync(deviceId, client ?? "Unknown", device ?? "Unknown", version ?? "1.0", Request.Headers); var sessionCreated = await _sessionManager.EnsureSessionAsync(deviceId, client ?? "Unknown", device ?? "Unknown", version ?? "1.0", Request.Headers);
if (sessionCreated)
{
_logger.LogInformation("✓ Session ensured for device {DeviceId}", deviceId);
// Give Jellyfin a moment to process the session creation
await Task.Delay(100);
}
else
{
_logger.LogWarning("⚠️ Failed to ensure session for device {DeviceId}", deviceId);
}
}
else
{
_logger.LogWarning("⚠️ No device ID found in headers - session cannot be created");
} }
// Parse the body to check if it's an external track // Parse the body to check if it's an external track

View File

@@ -42,6 +42,9 @@ public class JellyfinSessionManager
{ {
existingSession.LastActivity = DateTime.UtcNow; existingSession.LastActivity = DateTime.UtcNow;
_logger.LogDebug("Session already exists for device {DeviceId}", deviceId); _logger.LogDebug("Session already exists for device {DeviceId}", deviceId);
// Refresh capabilities to keep session alive
await PostCapabilitiesAsync(headers);
return true; return true;
} }
@@ -50,45 +53,22 @@ public class JellyfinSessionManager
try try
{ {
// Post session capabilities to Jellyfin - this creates the session // Post session capabilities to Jellyfin - this creates the session
var capabilities = new await PostCapabilitiesAsync(headers);
_logger.LogInformation("✓ Session created for {DeviceId}", deviceId);
// Track this session
_sessions[deviceId] = new SessionInfo
{ {
PlayableMediaTypes = new[] { "Audio" }, DeviceId = deviceId,
SupportedCommands = new[] Client = client,
{ Device = device,
"Play", Version = version,
"Playstate", LastActivity = DateTime.UtcNow,
"PlayNext" Headers = CloneHeaders(headers)
},
SupportsMediaControl = true,
SupportsPersistentIdentifier = true,
SupportsSync = false
}; };
var json = JsonSerializer.Serialize(capabilities); return true;
var (result, statusCode) = await _proxyService.PostJsonAsync("Sessions/Capabilities/Full", json, headers);
if (statusCode == 204 || statusCode == 200)
{
_logger.LogInformation("✓ Session created for {DeviceId}", deviceId);
// Track this session
_sessions[deviceId] = new SessionInfo
{
DeviceId = deviceId,
Client = client,
Device = device,
Version = version,
LastActivity = DateTime.UtcNow,
Headers = CloneHeaders(headers)
};
return true;
}
else
{
_logger.LogWarning("Failed to create session for {DeviceId} - status {StatusCode}", deviceId, statusCode);
return false;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -97,6 +77,34 @@ public class JellyfinSessionManager
} }
} }
/// <summary>
/// Posts session capabilities to Jellyfin.
/// </summary>
private async Task PostCapabilitiesAsync(IHeaderDictionary headers)
{
var capabilities = new
{
PlayableMediaTypes = new[] { "Audio" },
SupportedCommands = new[]
{
"Play",
"Playstate",
"PlayNext"
},
SupportsMediaControl = true,
SupportsPersistentIdentifier = true,
SupportsSync = false
};
var json = JsonSerializer.Serialize(capabilities);
var (result, statusCode) = await _proxyService.PostJsonAsync("Sessions/Capabilities/Full", json, headers);
if (statusCode != 204 && statusCode != 200)
{
_logger.LogWarning("Failed to post capabilities - status {StatusCode}", statusCode);
}
}
/// <summary> /// <summary>
/// Updates session activity timestamp. /// Updates session activity timestamp.
/// </summary> /// </summary>
@@ -150,18 +158,7 @@ public class JellyfinSessionManager
try try
{ {
// Post capabilities again to keep session alive // Post capabilities again to keep session alive
var capabilities = new await PostCapabilitiesAsync(session.Headers);
{
PlayableMediaTypes = new[] { "Audio" },
SupportedCommands = new[] { "Play", "Playstate", "PlayNext" },
SupportsMediaControl = true,
SupportsPersistentIdentifier = true,
SupportsSync = false
};
var json = JsonSerializer.Serialize(capabilities);
await _proxyService.PostJsonAsync("Sessions/Capabilities/Full", json, session.Headers);
_logger.LogDebug("✓ Kept session alive for {DeviceId}", session.DeviceId); _logger.LogDebug("✓ Kept session alive for {DeviceId}", session.DeviceId);
} }
catch (Exception ex) catch (Exception ex)