diff --git a/Emby.Server.Implementations/SyncPlay/GroupController.cs b/Emby.Server.Implementations/SyncPlay/Group.cs
similarity index 91%
rename from Emby.Server.Implementations/SyncPlay/GroupController.cs
rename to Emby.Server.Implementations/SyncPlay/Group.cs
index 16acae99e8..e32f5e25dc 100644
--- a/Emby.Server.Implementations/SyncPlay/GroupController.cs
+++ b/Emby.Server.Implementations/SyncPlay/Group.cs
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
-using Jellyfin.Data.Enums;
-using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.SyncPlay;
@@ -19,17 +16,17 @@ using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.SyncPlay
{
///
- /// Class GroupController.
+ /// Class Group.
///
///
/// Class is not thread-safe, external locking is required when accessing methods.
///
- public class GroupController : IGroupController, IGroupStateContext
+ public class Group : IGroupStateContext
{
///
/// The logger.
///
- private readonly ILogger _logger;
+ private readonly ILogger _logger;
///
/// The logger factory.
@@ -63,13 +60,13 @@ namespace Emby.Server.Implementations.SyncPlay
private IGroupState _state;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The logger factory.
/// The user manager.
/// The session manager.
/// The library manager.
- public GroupController(
+ public Group(
ILoggerFactory loggerFactory,
IUserManager userManager,
ISessionManager sessionManager,
@@ -79,7 +76,7 @@ namespace Emby.Server.Implementations.SyncPlay
_userManager = userManager;
_sessionManager = sessionManager;
_libraryManager = libraryManager;
- _logger = loggerFactory.CreateLogger();
+ _logger = loggerFactory.CreateLogger();
_state = new IdleGroupState(loggerFactory);
}
@@ -235,10 +232,18 @@ namespace Emby.Server.Implementations.SyncPlay
return !usersWithNoAccess.Any();
}
- ///
+ ///
+ /// Checks if the group is empty.
+ ///
+ /// true if the group is empty, false otherwise.
public bool IsGroupEmpty() => _participants.Count == 0;
- ///
+ ///
+ /// Initializes the group with the session's info.
+ ///
+ /// The session.
+ /// The request.
+ /// The cancellation token.
public void CreateGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken)
{
GroupName = request.GroupName;
@@ -273,7 +278,12 @@ namespace Emby.Server.Implementations.SyncPlay
_logger.LogInformation("Session {SessionId} created group {GroupId}.", session.Id, GroupId.ToString());
}
- ///
+ ///
+ /// Adds the session to the group.
+ ///
+ /// The session.
+ /// The request.
+ /// The cancellation token.
public void SessionJoin(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken)
{
AddSession(session);
@@ -289,21 +299,12 @@ namespace Emby.Server.Implementations.SyncPlay
_logger.LogInformation("Session {SessionId} joined group {GroupId}.", session.Id, GroupId.ToString());
}
- ///
- public void SessionRestore(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken)
- {
- var updateSession = NewSyncPlayGroupUpdate(GroupUpdateType.GroupJoined, GetInfo());
- SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken);
-
- var updateOthers = NewSyncPlayGroupUpdate(GroupUpdateType.UserJoined, session.UserName);
- SendGroupUpdate(session, SyncPlayBroadcastType.AllExceptCurrentSession, updateOthers, cancellationToken);
-
- _state.SessionJoined(this, _state.Type, session, cancellationToken);
-
- _logger.LogInformation("Session {SessionId} re-joined group {GroupId}.", session.Id, GroupId.ToString());
- }
-
- ///
+ ///
+ /// Removes the session from the group.
+ ///
+ /// The session.
+ /// The request.
+ /// The cancellation token.
public void SessionLeave(SessionInfo session, LeaveGroupRequest request, CancellationToken cancellationToken)
{
_state.SessionLeaving(this, _state.Type, session, cancellationToken);
@@ -319,7 +320,12 @@ namespace Emby.Server.Implementations.SyncPlay
_logger.LogInformation("Session {SessionId} left group {GroupId}.", session.Id, GroupId.ToString());
}
- ///
+ ///
+ /// Handles the requested action by the session.
+ ///
+ /// The session.
+ /// The requested action.
+ /// The cancellation token.
public void HandleRequest(SessionInfo session, IGroupPlaybackRequest request, CancellationToken cancellationToken)
{
// The server's job is to maintain a consistent state for clients to reference
@@ -329,14 +335,21 @@ namespace Emby.Server.Implementations.SyncPlay
request.Apply(this, _state, session, cancellationToken);
}
- ///
+ ///
+ /// Gets the info about the group for the clients.
+ ///
+ /// The group info for the clients.
public GroupInfoDto GetInfo()
{
var participants = _participants.Values.Select(session => session.Session.UserName).Distinct().ToList();
return new GroupInfoDto(GroupId, GroupName, _state.Type, participants, DateTime.UtcNow);
}
- ///
+ ///
+ /// Checks if a user has access to all content in the play queue.
+ ///
+ /// The user.
+ /// true if the user can access the play queue; false otherwise.
public bool HasAccessToPlayQueue(User user)
{
var items = PlayQueue.GetPlaylist().Select(item => item.ItemId).ToList();
diff --git a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs
index 0410048c4f..b2422f8e6e 100644
--- a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs
+++ b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs
@@ -44,20 +44,20 @@ namespace Emby.Server.Implementations.SyncPlay
///
/// The map between sessions and groups.
///
- private readonly Dictionary _sessionToGroupMap =
- new Dictionary(StringComparer.OrdinalIgnoreCase);
+ private readonly Dictionary _sessionToGroupMap =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
///
/// The groups.
///
- private readonly Dictionary _groups =
- new Dictionary();
+ private readonly Dictionary _groups =
+ new Dictionary();
///
/// Lock used for accessing any group.
///
///
- /// Always lock before and before locking on any .
+ /// Always lock before and before locking on any .
///
private readonly object _groupsLock = new object();
@@ -65,7 +65,7 @@ namespace Emby.Server.Implementations.SyncPlay
/// Lock used for accessing the session-to-group map.
///
///
- /// Always lock after and before locking on any .
+ /// Always lock after and before locking on any .
///
private readonly object _mapsLock = new object();
@@ -115,7 +115,7 @@ namespace Emby.Server.Implementations.SyncPlay
LeaveGroup(session, leaveGroupRequest, cancellationToken);
}
- var group = new GroupController(_loggerFactory, _userManager, _sessionManager, _libraryManager);
+ var group = new Group(_loggerFactory, _userManager, _sessionManager, _libraryManager);
_groups[group.GroupId] = group;
AddSessionToGroup(session, group);
@@ -132,7 +132,7 @@ namespace Emby.Server.Implementations.SyncPlay
// Locking required to access list of groups.
lock (_groupsLock)
{
- _groups.TryGetValue(request.GroupId, out IGroupController group);
+ _groups.TryGetValue(request.GroupId, out Group group);
if (group == null)
{
@@ -162,7 +162,8 @@ namespace Emby.Server.Implementations.SyncPlay
{
if (FindJoinedGroupId(session).Equals(request.GroupId))
{
- group.SessionRestore(session, request, cancellationToken);
+ // Restore session.
+ group.SessionJoin(session, request, cancellationToken);
return;
}
@@ -240,7 +241,7 @@ namespace Emby.Server.Implementations.SyncPlay
///
public void HandleRequest(SessionInfo session, IGroupPlaybackRequest request, CancellationToken cancellationToken)
{
- IGroupController group;
+ Group group;
lock (_mapsLock)
{
group = FindJoinedGroup(session);
@@ -255,7 +256,7 @@ namespace Emby.Server.Implementations.SyncPlay
return;
}
- // Group lock required as GroupController is not thread-safe.
+ // Group lock required as Group is not thread-safe.
lock (group)
{
group.HandleRequest(session, request, cancellationToken);
@@ -317,7 +318,7 @@ namespace Emby.Server.Implementations.SyncPlay
///
/// The session.
/// The group.
- private IGroupController FindJoinedGroup(SessionInfo session)
+ private Group FindJoinedGroup(SessionInfo session)
{
_sessionToGroupMap.TryGetValue(session.Id, out var group);
return group;
@@ -345,7 +346,7 @@ namespace Emby.Server.Implementations.SyncPlay
/// The session.
/// The group.
/// Thrown when the user is in another group already.
- private void AddSessionToGroup(SessionInfo session, IGroupController group)
+ private void AddSessionToGroup(SessionInfo session, Group group)
{
if (session == null)
{
@@ -369,7 +370,7 @@ namespace Emby.Server.Implementations.SyncPlay
/// The session.
/// The group.
/// Thrown when the user is not found in the specified group.
- private void RemoveSessionFromGroup(SessionInfo session, IGroupController group)
+ private void RemoveSessionFromGroup(SessionInfo session, Group group)
{
if (session == null)
{
diff --git a/MediaBrowser.Controller/SyncPlay/IGroupController.cs b/MediaBrowser.Controller/SyncPlay/IGroupController.cs
deleted file mode 100644
index 07f9659dd1..0000000000
--- a/MediaBrowser.Controller/SyncPlay/IGroupController.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-using System;
-using System.Threading;
-using Jellyfin.Data.Entities;
-using MediaBrowser.Controller.Session;
-using MediaBrowser.Controller.SyncPlay.Queue;
-using MediaBrowser.Controller.SyncPlay.Requests;
-using MediaBrowser.Model.SyncPlay;
-
-namespace MediaBrowser.Controller.SyncPlay
-{
- ///
- /// Interface IGroupController.
- ///
- public interface IGroupController
- {
- ///
- /// Gets the group identifier.
- ///
- /// The group identifier.
- Guid GroupId { get; }
-
- ///
- /// Gets the play queue.
- ///
- /// The play queue.
- PlayQueueManager PlayQueue { get; }
-
- ///
- /// Checks if the group is empty.
- ///
- /// true if the group is empty, false otherwise.
- bool IsGroupEmpty();
-
- ///
- /// Initializes the group with the session's info.
- ///
- /// The session.
- /// The request.
- /// The cancellation token.
- void CreateGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken);
-
- ///
- /// Adds the session to the group.
- ///
- /// The session.
- /// The request.
- /// The cancellation token.
- void SessionJoin(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken);
-
- ///
- /// Restores the state of a session that already joined the group.
- ///
- /// The session.
- /// The request.
- /// The cancellation token.
- void SessionRestore(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken);
-
- ///
- /// Removes the session from the group.
- ///
- /// The session.
- /// The request.
- /// The cancellation token.
- void SessionLeave(SessionInfo session, LeaveGroupRequest request, CancellationToken cancellationToken);
-
- ///
- /// Handles the requested action by the session.
- ///
- /// The session.
- /// The requested action.
- /// The cancellation token.
- void HandleRequest(SessionInfo session, IGroupPlaybackRequest request, CancellationToken cancellationToken);
-
- ///
- /// Gets the info about the group for the clients.
- ///
- /// The group info for the clients.
- GroupInfoDto GetInfo();
-
- ///
- /// Checks if a user has access to all content in the play queue.
- ///
- /// The user.
- /// true if the user can access the play queue; false otherwise.
- bool HasAccessToPlayQueue(User user);
- }
-}