mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-22 01:54:42 +01:00
Merge pull request #5648 from OancaAndrei/syncplay-sessions-fix
Fix session references in SyncPlay
This commit is contained in:
@@ -164,26 +164,26 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
/// <summary>
|
||||
/// Filters sessions of this group.
|
||||
/// </summary>
|
||||
/// <param name="from">The current session.</param>
|
||||
/// <param name="fromId">The current session identifier.</param>
|
||||
/// <param name="type">The filtering type.</param>
|
||||
/// <returns>The list of sessions matching the filter.</returns>
|
||||
private IEnumerable<SessionInfo> FilterSessions(SessionInfo from, SyncPlayBroadcastType type)
|
||||
private IEnumerable<string> FilterSessions(string fromId, SyncPlayBroadcastType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
SyncPlayBroadcastType.CurrentSession => new SessionInfo[] { from },
|
||||
SyncPlayBroadcastType.CurrentSession => new string[] { fromId },
|
||||
SyncPlayBroadcastType.AllGroup => _participants
|
||||
.Values
|
||||
.Select(session => session.Session),
|
||||
.Select(member => member.SessionId),
|
||||
SyncPlayBroadcastType.AllExceptCurrentSession => _participants
|
||||
.Values
|
||||
.Select(session => session.Session)
|
||||
.Where(session => !session.Id.Equals(from.Id, StringComparison.OrdinalIgnoreCase)),
|
||||
.Select(member => member.SessionId)
|
||||
.Where(sessionId => !sessionId.Equals(fromId, StringComparison.OrdinalIgnoreCase)),
|
||||
SyncPlayBroadcastType.AllReady => _participants
|
||||
.Values
|
||||
.Where(session => !session.IsBuffering)
|
||||
.Select(session => session.Session),
|
||||
_ => Enumerable.Empty<SessionInfo>()
|
||||
.Where(member => !member.IsBuffering)
|
||||
.Select(member => member.SessionId),
|
||||
_ => Enumerable.Empty<string>()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
// Get list of users.
|
||||
var users = _participants
|
||||
.Values
|
||||
.Select(participant => _userManager.GetUserById(participant.Session.UserId));
|
||||
.Select(participant => _userManager.GetUserById(participant.UserId));
|
||||
|
||||
// Find problematic users.
|
||||
var usersWithNoAccess = users.Where(user => !HasAccessToQueue(user, queue));
|
||||
@@ -353,7 +353,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
/// <returns>The group info for the clients.</returns>
|
||||
public GroupInfoDto GetInfo()
|
||||
{
|
||||
var participants = _participants.Values.Select(session => session.Session.UserName).Distinct().ToList();
|
||||
var participants = _participants.Values.Select(session => session.UserName).Distinct().ToList();
|
||||
return new GroupInfoDto(GroupId, GroupName, _state.Type, participants, DateTime.UtcNow);
|
||||
}
|
||||
|
||||
@@ -389,9 +389,9 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
{
|
||||
IEnumerable<Task> GetTasks()
|
||||
{
|
||||
foreach (var session in FilterSessions(from, type))
|
||||
foreach (var sessionId in FilterSessions(from.Id, type))
|
||||
{
|
||||
yield return _sessionManager.SendSyncPlayGroupUpdate(session, message, cancellationToken);
|
||||
yield return _sessionManager.SendSyncPlayGroupUpdate(sessionId, message, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,9 +403,9 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
{
|
||||
IEnumerable<Task> GetTasks()
|
||||
{
|
||||
foreach (var session in FilterSessions(from, type))
|
||||
foreach (var sessionId in FilterSessions(from.Id, type))
|
||||
{
|
||||
yield return _sessionManager.SendSyncPlayCommand(session, message, cancellationToken);
|
||||
yield return _sessionManager.SendSyncPlayCommand(sessionId, message, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,8 +659,9 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
public PlayQueueUpdate GetPlayQueueUpdate(PlayQueueUpdateReason reason)
|
||||
{
|
||||
var startPositionTicks = PositionTicks;
|
||||
var isPlaying = _state.Type.Equals(GroupStateType.Playing);
|
||||
|
||||
if (_state.Type.Equals(GroupStateType.Playing))
|
||||
if (isPlaying)
|
||||
{
|
||||
var currentTime = DateTime.UtcNow;
|
||||
var elapsedTime = currentTime - LastActivity;
|
||||
@@ -679,6 +680,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
PlayQueue.GetPlaylist(),
|
||||
PlayQueue.PlayingItemIndex,
|
||||
startPositionTicks,
|
||||
isPlaying,
|
||||
PlayQueue.ShuffleMode,
|
||||
PlayQueue.RepeatMode);
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
_logger.LogWarning("Session {SessionId} tried to join group {GroupId} that does not exist.", session.Id, request.GroupId);
|
||||
|
||||
var error = new GroupUpdate<string>(Guid.Empty, GroupUpdateType.GroupDoesNotExist, string.Empty);
|
||||
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
||||
_sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
_logger.LogWarning("Session {SessionId} tried to join group {GroupId} but does not have access to some content of the playing queue.", session.Id, group.GroupId.ToString());
|
||||
|
||||
var error = new GroupUpdate<string>(group.GroupId, GroupUpdateType.LibraryAccessDenied, string.Empty);
|
||||
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
||||
_sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
_logger.LogWarning("Session {SessionId} does not belong to any group.", session.Id);
|
||||
|
||||
var error = new GroupUpdate<string>(Guid.Empty, GroupUpdateType.NotInGroup, string.Empty);
|
||||
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
||||
_sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -329,7 +329,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
||||
_logger.LogWarning("Session {SessionId} does not belong to any group.", session.Id);
|
||||
|
||||
var error = new GroupUpdate<string>(Guid.Empty, GroupUpdateType.NotInGroup, string.Empty);
|
||||
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
||||
_sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user