2020-04-01 15:52:42 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
2020-05-27 00:52:05 +00:00
|
|
|
using Jellyfin.Data.Enums;
|
2020-04-01 15:52:42 +00:00
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Session;
|
2020-05-06 21:42:53 +00:00
|
|
|
using MediaBrowser.Controller.SyncPlay;
|
|
|
|
using MediaBrowser.Model.SyncPlay;
|
2020-05-27 00:52:05 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-04-01 15:52:42 +00:00
|
|
|
|
2020-05-06 21:42:53 +00:00
|
|
|
namespace Emby.Server.Implementations.SyncPlay
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
2020-05-06 21:42:53 +00:00
|
|
|
/// Class SyncPlayManager.
|
2020-04-01 15:52:42 +00:00
|
|
|
/// </summary>
|
2020-05-06 21:42:53 +00:00
|
|
|
public class SyncPlayManager : ISyncPlayManager, IDisposable
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The logger.
|
|
|
|
/// </summary>
|
2020-06-06 00:15:56 +00:00
|
|
|
private readonly ILogger<SyncPlayManager> _logger;
|
2020-04-01 15:52:42 +00:00
|
|
|
|
2020-04-04 15:59:16 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The user manager.
|
|
|
|
/// </summary>
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
2020-04-01 15:52:42 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The session manager.
|
|
|
|
/// </summary>
|
|
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
|
2020-04-04 22:50:57 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The library manager.
|
|
|
|
/// </summary>
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
2020-04-01 15:52:42 +00:00
|
|
|
/// <summary>
|
2020-04-04 15:56:21 +00:00
|
|
|
/// The map between sessions and groups.
|
2020-04-01 15:52:42 +00:00
|
|
|
/// </summary>
|
2020-09-24 21:04:21 +00:00
|
|
|
private readonly Dictionary<string, ISyncPlayGroupController> _sessionToGroupMap =
|
|
|
|
new Dictionary<string, ISyncPlayGroupController>(StringComparer.OrdinalIgnoreCase);
|
2020-04-01 15:52:42 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The groups.
|
|
|
|
/// </summary>
|
2020-09-24 21:04:21 +00:00
|
|
|
private readonly Dictionary<Guid, ISyncPlayGroupController> _groups =
|
|
|
|
new Dictionary<Guid, ISyncPlayGroupController>();
|
2020-04-28 12:12:06 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Lock used for accesing any group.
|
|
|
|
/// </summary>
|
|
|
|
private readonly object _groupsLock = new object();
|
2020-04-01 15:52:42 +00:00
|
|
|
|
|
|
|
private bool _disposed = false;
|
|
|
|
|
2020-05-29 09:28:19 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="SyncPlayManager" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
|
|
|
/// <param name="sessionManager">The session manager.</param>
|
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
2020-05-06 21:42:53 +00:00
|
|
|
public SyncPlayManager(
|
|
|
|
ILogger<SyncPlayManager> logger,
|
2020-04-04 15:59:16 +00:00
|
|
|
IUserManager userManager,
|
2020-04-04 22:50:57 +00:00
|
|
|
ISessionManager sessionManager,
|
|
|
|
ILibraryManager libraryManager)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
|
|
|
_logger = logger;
|
2020-04-04 15:59:16 +00:00
|
|
|
_userManager = userManager;
|
2020-04-01 15:52:42 +00:00
|
|
|
_sessionManager = sessionManager;
|
2020-04-04 22:50:57 +00:00
|
|
|
_libraryManager = libraryManager;
|
2020-04-01 15:52:42 +00:00
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.SessionStarted += OnSessionManagerSessionStarted;
|
2020-04-21 21:37:37 +00:00
|
|
|
_sessionManager.SessionEnded += OnSessionManagerSessionEnded;
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.PlaybackStart += OnSessionManagerPlaybackStart;
|
2020-04-21 21:37:37 +00:00
|
|
|
_sessionManager.PlaybackStopped += OnSessionManagerPlaybackStopped;
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets all groups.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>All groups.</value>
|
2020-09-24 21:04:21 +00:00
|
|
|
public IEnumerable<ISyncPlayGroupController> Groups => _groups.Values;
|
2020-04-01 15:52:42 +00:00
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Releases unmanaged and optionally managed resources.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
if (_disposed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.SessionStarted -= OnSessionManagerSessionStarted;
|
2020-04-21 21:37:37 +00:00
|
|
|
_sessionManager.SessionEnded -= OnSessionManagerSessionEnded;
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.PlaybackStart -= OnSessionManagerPlaybackStart;
|
2020-04-21 21:37:37 +00:00
|
|
|
_sessionManager.PlaybackStopped -= OnSessionManagerPlaybackStopped;
|
2020-04-01 15:52:42 +00:00
|
|
|
|
|
|
|
_disposed = true;
|
|
|
|
}
|
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
private void OnSessionManagerSessionStarted(object sender, SessionEventArgs e)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:56:21 +00:00
|
|
|
var session = e.SessionInfo;
|
2020-05-09 12:34:07 +00:00
|
|
|
if (!IsSessionInGroup(session))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
var groupId = GetSessionGroup(session) ?? Guid.Empty;
|
|
|
|
var request = new JoinGroupRequest()
|
|
|
|
{
|
|
|
|
GroupId = groupId
|
|
|
|
};
|
|
|
|
JoinGroup(session, groupId, request, CancellationToken.None);
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
private void OnSessionManagerSessionEnded(object sender, SessionEventArgs e)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-09-24 21:04:21 +00:00
|
|
|
var session = e.SessionInfo;
|
2020-05-09 12:34:07 +00:00
|
|
|
if (!IsSessionInGroup(session))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-21 13:46:50 +00:00
|
|
|
// TODO: probably remove this event, not used at the moment.
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
private void OnSessionManagerPlaybackStart(object sender, PlaybackProgressEventArgs e)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-09-24 21:04:21 +00:00
|
|
|
var session = e.Session;
|
|
|
|
if (!IsSessionInGroup(session))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-21 13:46:50 +00:00
|
|
|
// TODO: probably remove this event, not used at the moment.
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
private void OnSessionManagerPlaybackStopped(object sender, PlaybackStopEventArgs e)
|
2020-04-04 22:50:57 +00:00
|
|
|
{
|
2020-09-24 21:04:21 +00:00
|
|
|
var session = e.Session;
|
|
|
|
if (!IsSessionInGroup(session))
|
2020-04-04 22:50:57 +00:00
|
|
|
{
|
2020-09-24 21:04:21 +00:00
|
|
|
return;
|
2020-04-04 22:50:57 +00:00
|
|
|
}
|
2020-05-27 00:52:05 +00:00
|
|
|
|
2020-10-21 13:46:50 +00:00
|
|
|
// TODO: probably remove this event, not used at the moment.
|
2020-09-24 21:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private bool IsSessionInGroup(SessionInfo session)
|
|
|
|
{
|
|
|
|
return _sessionToGroupMap.ContainsKey(session.Id);
|
2020-04-04 22:50:57 +00:00
|
|
|
}
|
|
|
|
|
2020-04-04 15:56:21 +00:00
|
|
|
private Guid? GetSessionGroup(SessionInfo session)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-05-27 00:52:05 +00:00
|
|
|
_sessionToGroupMap.TryGetValue(session.Id, out var group);
|
2020-09-24 21:04:21 +00:00
|
|
|
return group?.GroupId;
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2020-09-24 21:04:21 +00:00
|
|
|
public void NewGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:59:16 +00:00
|
|
|
var user = _userManager.GetUserById(session.UserId);
|
|
|
|
|
2020-05-27 00:52:05 +00:00
|
|
|
if (user.SyncPlayAccess != SyncPlayAccess.CreateAndJoinGroups)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-05-04 17:46:02 +00:00
|
|
|
_logger.LogWarning("NewGroup: {0} does not have permission to create groups.", session.Id);
|
2020-04-22 20:05:53 +00:00
|
|
|
|
2020-07-12 21:55:03 +00:00
|
|
|
var error = new GroupUpdate<string>
|
2020-04-22 20:05:53 +00:00
|
|
|
{
|
|
|
|
Type = GroupUpdateType.CreateGroupDenied
|
|
|
|
};
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
2020-04-22 20:05:53 +00:00
|
|
|
return;
|
2020-04-04 15:59:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 12:12:06 +00:00
|
|
|
lock (_groupsLock)
|
2020-04-04 15:59:16 +00:00
|
|
|
{
|
2020-04-28 12:12:06 +00:00
|
|
|
if (IsSessionInGroup(session))
|
|
|
|
{
|
2020-05-04 17:46:02 +00:00
|
|
|
LeaveGroup(session, cancellationToken);
|
2020-04-28 12:12:06 +00:00
|
|
|
}
|
2020-04-01 15:52:42 +00:00
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
var group = new SyncPlayGroupController(_logger, _userManager, _sessionManager, _libraryManager, this);
|
|
|
|
_groups[group.GroupId] = group;
|
2020-04-01 15:52:42 +00:00
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
group.CreateGroup(session, request, cancellationToken);
|
2020-04-28 12:12:06 +00:00
|
|
|
}
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2020-05-09 12:34:07 +00:00
|
|
|
public void JoinGroup(SessionInfo session, Guid groupId, JoinGroupRequest request, CancellationToken cancellationToken)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:59:16 +00:00
|
|
|
var user = _userManager.GetUserById(session.UserId);
|
|
|
|
|
2020-05-27 00:52:05 +00:00
|
|
|
if (user.SyncPlayAccess == SyncPlayAccess.None)
|
2020-04-04 15:59:16 +00:00
|
|
|
{
|
2020-05-06 21:42:53 +00:00
|
|
|
_logger.LogWarning("JoinGroup: {0} does not have access to SyncPlay.", session.Id);
|
2020-04-22 20:05:53 +00:00
|
|
|
|
|
|
|
var error = new GroupUpdate<string>()
|
|
|
|
{
|
|
|
|
Type = GroupUpdateType.JoinGroupDenied
|
|
|
|
};
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
2020-04-22 20:05:53 +00:00
|
|
|
return;
|
2020-04-04 15:59:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 12:12:06 +00:00
|
|
|
lock (_groupsLock)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-09-24 21:04:21 +00:00
|
|
|
ISyncPlayGroupController group;
|
2020-04-28 12:12:06 +00:00
|
|
|
_groups.TryGetValue(groupId, out group);
|
2020-04-01 15:52:42 +00:00
|
|
|
|
2020-04-28 12:12:06 +00:00
|
|
|
if (group == null)
|
2020-04-22 20:05:53 +00:00
|
|
|
{
|
2020-05-04 17:46:02 +00:00
|
|
|
_logger.LogWarning("JoinGroup: {0} tried to join group {0} that does not exist.", session.Id, groupId);
|
2020-04-04 22:50:57 +00:00
|
|
|
|
2020-04-28 12:12:06 +00:00
|
|
|
var error = new GroupUpdate<string>()
|
|
|
|
{
|
2020-05-04 17:46:02 +00:00
|
|
|
Type = GroupUpdateType.GroupDoesNotExist
|
2020-04-28 12:12:06 +00:00
|
|
|
};
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
2020-04-28 12:12:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-22 20:05:53 +00:00
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
if (!group.HasAccessToPlayQueue(user))
|
2020-04-22 20:05:53 +00:00
|
|
|
{
|
2020-09-24 21:04:21 +00:00
|
|
|
_logger.LogWarning("JoinGroup: {0} does not have access to some content from the playing queue of group {1}.", session.Id, group.GroupId.ToString());
|
2020-04-28 12:12:06 +00:00
|
|
|
|
|
|
|
var error = new GroupUpdate<string>()
|
|
|
|
{
|
2020-09-24 21:04:21 +00:00
|
|
|
GroupId = group.GroupId.ToString(),
|
2020-04-28 12:12:06 +00:00
|
|
|
Type = GroupUpdateType.LibraryAccessDenied
|
|
|
|
};
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
2020-04-28 12:12:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSessionInGroup(session))
|
|
|
|
{
|
2020-05-09 12:34:07 +00:00
|
|
|
if (GetSessionGroup(session).Equals(groupId))
|
|
|
|
{
|
2020-09-24 21:04:21 +00:00
|
|
|
group.SessionRestore(session, request, cancellationToken);
|
2020-05-09 12:34:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-04 17:46:02 +00:00
|
|
|
LeaveGroup(session, cancellationToken);
|
2020-04-28 12:12:06 +00:00
|
|
|
}
|
2020-04-04 22:50:57 +00:00
|
|
|
|
2020-05-04 17:46:02 +00:00
|
|
|
group.SessionJoin(session, request, cancellationToken);
|
2020-04-21 21:37:37 +00:00
|
|
|
}
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2020-05-04 17:46:02 +00:00
|
|
|
public void LeaveGroup(SessionInfo session, CancellationToken cancellationToken)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-10-21 13:46:50 +00:00
|
|
|
// TODO: determine what happens to users that are in a group and get their permissions revoked.
|
2020-04-28 12:12:06 +00:00
|
|
|
lock (_groupsLock)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-05-28 18:21:26 +00:00
|
|
|
_sessionToGroupMap.TryGetValue(session.Id, out var group);
|
2020-04-01 15:52:42 +00:00
|
|
|
|
2020-04-28 12:12:06 +00:00
|
|
|
if (group == null)
|
2020-04-22 20:05:53 +00:00
|
|
|
{
|
2020-05-04 17:46:02 +00:00
|
|
|
_logger.LogWarning("LeaveGroup: {0} does not belong to any group.", session.Id);
|
2020-04-01 15:52:42 +00:00
|
|
|
|
2020-04-28 12:12:06 +00:00
|
|
|
var error = new GroupUpdate<string>()
|
|
|
|
{
|
|
|
|
Type = GroupUpdateType.NotInGroup
|
|
|
|
};
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
2020-04-28 12:12:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-04 17:46:02 +00:00
|
|
|
group.SessionLeave(session, cancellationToken);
|
2020-04-28 12:12:06 +00:00
|
|
|
|
|
|
|
if (group.IsGroupEmpty())
|
|
|
|
{
|
2020-09-24 21:04:21 +00:00
|
|
|
_logger.LogInformation("LeaveGroup: removing empty group {0}.", group.GroupId);
|
|
|
|
_groups.Remove(group.GroupId, out _);
|
2020-04-28 12:12:06 +00:00
|
|
|
}
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2020-09-24 21:04:21 +00:00
|
|
|
public List<GroupInfoDto> ListGroups(SessionInfo session)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:59:16 +00:00
|
|
|
var user = _userManager.GetUserById(session.UserId);
|
|
|
|
|
2020-05-27 00:52:05 +00:00
|
|
|
if (user.SyncPlayAccess == SyncPlayAccess.None)
|
2020-04-04 15:59:16 +00:00
|
|
|
{
|
2020-05-12 07:08:35 +00:00
|
|
|
return new List<GroupInfoDto>();
|
2020-04-04 15:59:16 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 21:04:21 +00:00
|
|
|
return _groups.Values.Where(
|
|
|
|
group => group.HasAccessToPlayQueue(user)).Select(
|
|
|
|
group => group.GetInfo()).ToList();
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2020-05-12 17:05:05 +00:00
|
|
|
public void HandleRequest(SessionInfo session, IPlaybackGroupRequest request, CancellationToken cancellationToken)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:59:16 +00:00
|
|
|
var user = _userManager.GetUserById(session.UserId);
|
|
|
|
|
2020-05-27 00:52:05 +00:00
|
|
|
if (user.SyncPlayAccess == SyncPlayAccess.None)
|
2020-04-04 15:59:16 +00:00
|
|
|
{
|
2020-05-06 21:42:53 +00:00
|
|
|
_logger.LogWarning("HandleRequest: {0} does not have access to SyncPlay.", session.Id);
|
2020-04-22 20:05:53 +00:00
|
|
|
|
|
|
|
var error = new GroupUpdate<string>()
|
|
|
|
{
|
|
|
|
Type = GroupUpdateType.JoinGroupDenied
|
|
|
|
};
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
2020-04-22 20:05:53 +00:00
|
|
|
return;
|
2020-04-04 15:59:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 12:12:06 +00:00
|
|
|
lock (_groupsLock)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-05-28 18:21:26 +00:00
|
|
|
_sessionToGroupMap.TryGetValue(session.Id, out var group);
|
2020-04-01 15:52:42 +00:00
|
|
|
|
2020-04-28 12:12:06 +00:00
|
|
|
if (group == null)
|
2020-04-22 20:05:53 +00:00
|
|
|
{
|
2020-05-04 17:46:02 +00:00
|
|
|
_logger.LogWarning("HandleRequest: {0} does not belong to any group.", session.Id);
|
2020-04-28 12:12:06 +00:00
|
|
|
|
|
|
|
var error = new GroupUpdate<string>()
|
|
|
|
{
|
|
|
|
Type = GroupUpdateType.NotInGroup
|
|
|
|
};
|
2020-09-24 21:04:21 +00:00
|
|
|
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
|
2020-04-28 12:12:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-04 17:46:02 +00:00
|
|
|
group.HandleRequest(session, request, cancellationToken);
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-15 16:03:58 +00:00
|
|
|
|
2020-04-01 15:52:42 +00:00
|
|
|
/// <inheritdoc />
|
2020-09-24 21:04:21 +00:00
|
|
|
public void AddSessionToGroup(SessionInfo session, ISyncPlayGroupController group)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:56:21 +00:00
|
|
|
if (IsSessionInGroup(session))
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:56:21 +00:00
|
|
|
throw new InvalidOperationException("Session in other group already!");
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
2020-05-26 09:37:52 +00:00
|
|
|
|
2020-04-04 15:56:21 +00:00
|
|
|
_sessionToGroupMap[session.Id] = group;
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2020-09-24 21:04:21 +00:00
|
|
|
public void RemoveSessionFromGroup(SessionInfo session, ISyncPlayGroupController group)
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:56:21 +00:00
|
|
|
if (!IsSessionInGroup(session))
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:56:21 +00:00
|
|
|
throw new InvalidOperationException("Session not in any group!");
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 18:21:26 +00:00
|
|
|
_sessionToGroupMap.Remove(session.Id, out var tempGroup);
|
2020-09-24 21:04:21 +00:00
|
|
|
if (!tempGroup.GroupId.Equals(group.GroupId))
|
2020-04-01 15:52:42 +00:00
|
|
|
{
|
2020-04-04 15:56:21 +00:00
|
|
|
throw new InvalidOperationException("Session was in wrong group!");
|
2020-04-01 15:52:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|