aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIonut Andrei Oanca <oancaionutandrei@gmail.com>2021-03-28 13:25:40 +0200
committerIonut Andrei Oanca <oancaionutandrei@gmail.com>2021-03-28 13:25:40 +0200
commit9eb740ba57c7d8dfbffac9e18541c969eb0af880 (patch)
tree68566f387b23972ab475569e50eaf69495cbe63e
parent9fe3ca7a92ac12ebb0fc88c5458bc8568458a478 (diff)
Fix storing outdated sessions in SyncPlay
-rw-r--r--Emby.Server.Implementations/Session/SessionManager.cs6
-rw-r--r--Emby.Server.Implementations/SyncPlay/Group.cs30
-rw-r--r--Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs8
-rw-r--r--MediaBrowser.Controller/Session/ISessionManager.cs8
-rw-r--r--MediaBrowser.Controller/SyncPlay/GroupMember.cs23
5 files changed, 46 insertions, 29 deletions
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs
index 10e28c33a..0dc87c844 100644
--- a/Emby.Server.Implementations/Session/SessionManager.cs
+++ b/Emby.Server.Implementations/Session/SessionManager.cs
@@ -1197,16 +1197,18 @@ namespace Emby.Server.Implementations.Session
}
/// <inheritdoc />
- public async Task SendSyncPlayCommand(SessionInfo session, SendCommand command, CancellationToken cancellationToken)
+ public async Task SendSyncPlayCommand(string sessionId, SendCommand command, CancellationToken cancellationToken)
{
CheckDisposed();
+ var session = GetSession(sessionId);
await SendMessageToSession(session, SessionMessageType.SyncPlayCommand, command, cancellationToken).ConfigureAwait(false);
}
/// <inheritdoc />
- public async Task SendSyncPlayGroupUpdate<T>(SessionInfo session, GroupUpdate<T> command, CancellationToken cancellationToken)
+ public async Task SendSyncPlayGroupUpdate<T>(string sessionId, GroupUpdate<T> command, CancellationToken cancellationToken)
{
CheckDisposed();
+ var session = GetSession(sessionId);
await SendMessageToSession(session, SessionMessageType.SyncPlayGroupUpdate, command, cancellationToken).ConfigureAwait(false);
}
diff --git a/Emby.Server.Implementations/SyncPlay/Group.cs b/Emby.Server.Implementations/SyncPlay/Group.cs
index 7c2ad2477..2fd971c9d 100644
--- a/Emby.Server.Implementations/SyncPlay/Group.cs
+++ b/Emby.Server.Implementations/SyncPlay/Group.cs
@@ -162,26 +162,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>()
};
}
@@ -223,7 +223,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));
@@ -351,7 +351,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);
}
@@ -387,9 +387,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);
}
}
@@ -401,9 +401,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);
}
}
diff --git a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs
index aee959c53..3ebdbcf9a 100644
--- a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs
+++ b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs
@@ -158,7 +158,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;
}
@@ -170,7 +170,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;
}
@@ -247,7 +247,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;
}
}
@@ -324,7 +324,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);
}
}
diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs
index 6c06dcad5..d22c9c6cf 100644
--- a/MediaBrowser.Controller/Session/ISessionManager.cs
+++ b/MediaBrowser.Controller/Session/ISessionManager.cs
@@ -156,20 +156,20 @@ namespace MediaBrowser.Controller.Session
/// <summary>
/// Sends a SyncPlayCommand to a session.
/// </summary>
- /// <param name="session">The session.</param>
+ /// <param name="sessionId">The identifier of the session.</param>
/// <param name="command">The command.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
- Task SendSyncPlayCommand(SessionInfo session, SendCommand command, CancellationToken cancellationToken);
+ Task SendSyncPlayCommand(string sessionId, SendCommand command, CancellationToken cancellationToken);
/// <summary>
/// Sends a SyncPlayGroupUpdate to a session.
/// </summary>
- /// <param name="session">The session.</param>
+ /// <param name="sessionId">The identifier of the session.</param>
/// <param name="command">The group update.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
- Task SendSyncPlayGroupUpdate<T>(SessionInfo session, GroupUpdate<T> command, CancellationToken cancellationToken);
+ Task SendSyncPlayGroupUpdate<T>(string sessionId, GroupUpdate<T> command, CancellationToken cancellationToken);
/// <summary>
/// Sends the browse command.
diff --git a/MediaBrowser.Controller/SyncPlay/GroupMember.cs b/MediaBrowser.Controller/SyncPlay/GroupMember.cs
index 5fb982e85..361c91d53 100644
--- a/MediaBrowser.Controller/SyncPlay/GroupMember.cs
+++ b/MediaBrowser.Controller/SyncPlay/GroupMember.cs
@@ -1,3 +1,4 @@
+using System;
using MediaBrowser.Controller.Session;
namespace MediaBrowser.Controller.SyncPlay
@@ -13,14 +14,28 @@ namespace MediaBrowser.Controller.SyncPlay
/// <param name="session">The session.</param>
public GroupMember(SessionInfo session)
{
- Session = session;
+ SessionId = session.Id;
+ UserId = session.UserId;
+ UserName = session.UserName;
}
/// <summary>
- /// Gets the session.
+ /// Gets the identifier of the session.
/// </summary>
- /// <value>The session.</value>
- public SessionInfo Session { get; }
+ /// <value>The session identifier.</value>
+ public string SessionId { get; }
+
+ /// <summary>
+ /// Gets the identifier of the user.
+ /// </summary>
+ /// <value>The user identifier.</value>
+ public Guid UserId { get; }
+
+ /// <summary>
+ /// Gets the username.
+ /// </summary>
+ /// <value>The username.</value>
+ public string UserName { get; }
/// <summary>
/// Gets or sets the ping, in milliseconds.