mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
lets try that again
This commit is contained in:
@@ -1789,7 +1789,22 @@ public class JellyfinController : ControllerBase
|
||||
var (deviceId, client, device, version) = ExtractDeviceInfo(Request.Headers);
|
||||
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
|
||||
|
||||
@@ -42,6 +42,9 @@ public class JellyfinSessionManager
|
||||
{
|
||||
existingSession.LastActivity = DateTime.UtcNow;
|
||||
_logger.LogDebug("Session already exists for device {DeviceId}", deviceId);
|
||||
|
||||
// Refresh capabilities to keep session alive
|
||||
await PostCapabilitiesAsync(headers);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -50,45 +53,22 @@ public class JellyfinSessionManager
|
||||
try
|
||||
{
|
||||
// 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" },
|
||||
SupportedCommands = new[]
|
||||
{
|
||||
"Play",
|
||||
"Playstate",
|
||||
"PlayNext"
|
||||
},
|
||||
SupportsMediaControl = true,
|
||||
SupportsPersistentIdentifier = true,
|
||||
SupportsSync = false
|
||||
DeviceId = deviceId,
|
||||
Client = client,
|
||||
Device = device,
|
||||
Version = version,
|
||||
LastActivity = DateTime.UtcNow,
|
||||
Headers = CloneHeaders(headers)
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(capabilities);
|
||||
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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
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>
|
||||
/// Updates session activity timestamp.
|
||||
/// </summary>
|
||||
@@ -150,18 +158,7 @@ public class JellyfinSessionManager
|
||||
try
|
||||
{
|
||||
// Post capabilities again to keep session alive
|
||||
var capabilities = new
|
||||
{
|
||||
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);
|
||||
|
||||
await PostCapabilitiesAsync(session.Headers);
|
||||
_logger.LogDebug("✓ Kept session alive for {DeviceId}", session.DeviceId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user