Patch data-races and minor changes in SyncPlay

This commit is contained in:
Ionut Andrei Oanca 2020-11-15 17:03:27 +01:00
parent 5d77f422f0
commit c7e53bce2f
20 changed files with 383 additions and 385 deletions

View File

@ -45,11 +45,6 @@ namespace Emby.Server.Implementations.SyncPlay
/// </summary> /// </summary>
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
/// <summary>
/// The SyncPlay manager.
/// </summary>
private readonly ISyncPlayManager _syncPlayManager;
/// <summary> /// <summary>
/// Internal group state. /// Internal group state.
/// </summary> /// </summary>
@ -63,19 +58,16 @@ namespace Emby.Server.Implementations.SyncPlay
/// <param name="userManager">The user manager.</param> /// <param name="userManager">The user manager.</param>
/// <param name="sessionManager">The session manager.</param> /// <param name="sessionManager">The session manager.</param>
/// <param name="libraryManager">The library manager.</param> /// <param name="libraryManager">The library manager.</param>
/// <param name="syncPlayManager">The SyncPlay manager.</param>
public GroupController( public GroupController(
ILogger logger, ILogger logger,
IUserManager userManager, IUserManager userManager,
ISessionManager sessionManager, ISessionManager sessionManager,
ILibraryManager libraryManager, ILibraryManager libraryManager)
ISyncPlayManager syncPlayManager)
{ {
_logger = logger; _logger = logger;
_userManager = userManager; _userManager = userManager;
_sessionManager = sessionManager; _sessionManager = sessionManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_syncPlayManager = syncPlayManager;
_state = new IdleGroupState(_logger); _state = new IdleGroupState(_logger);
} }
@ -168,7 +160,7 @@ namespace Emby.Server.Implementations.SyncPlay
/// </summary> /// </summary>
/// <param name="from">The current session.</param> /// <param name="from">The current session.</param>
/// <param name="type">The filtering type.</param> /// <param name="type">The filtering type.</param>
/// <returns>The array of sessions matching the filter.</returns> /// <returns>The list of sessions matching the filter.</returns>
private IEnumerable<SessionInfo> FilterSessions(SessionInfo from, SyncPlayBroadcastType type) private IEnumerable<SessionInfo> FilterSessions(SessionInfo from, SyncPlayBroadcastType type)
{ {
return type switch return type switch
@ -209,7 +201,7 @@ namespace Emby.Server.Implementations.SyncPlay
/// <param name="user">The user.</param> /// <param name="user">The user.</param>
/// <param name="queue">The queue.</param> /// <param name="queue">The queue.</param>
/// <returns><c>true</c> if the user can access all the items in the queue, <c>false</c> otherwise.</returns> /// <returns><c>true</c> if the user can access all the items in the queue, <c>false</c> otherwise.</returns>
private bool HasAccessToQueue(User user, IEnumerable<Guid> queue) private bool HasAccessToQueue(User user, IReadOnlyList<Guid> queue)
{ {
// Check if queue is empty. // Check if queue is empty.
if (!queue?.Any() ?? true) if (!queue?.Any() ?? true)
@ -234,7 +226,7 @@ namespace Emby.Server.Implementations.SyncPlay
return true; return true;
} }
private bool AllUsersHaveAccessToQueue(IEnumerable<Guid> queue) private bool AllUsersHaveAccessToQueue(IReadOnlyList<Guid> queue)
{ {
// Check if queue is empty. // Check if queue is empty.
if (!queue?.Any() ?? true) if (!queue?.Any() ?? true)
@ -262,7 +254,6 @@ namespace Emby.Server.Implementations.SyncPlay
{ {
GroupName = request.GroupName; GroupName = request.GroupName;
AddSession(session); AddSession(session);
_syncPlayManager.AddSessionToGroup(session, this);
var sessionIsPlayingAnItem = session.FullNowPlayingItem != null; var sessionIsPlayingAnItem = session.FullNowPlayingItem != null;
@ -270,7 +261,7 @@ namespace Emby.Server.Implementations.SyncPlay
if (sessionIsPlayingAnItem) if (sessionIsPlayingAnItem)
{ {
var playlist = session.NowPlayingQueue.Select(item => item.Id); var playlist = session.NowPlayingQueue.Select(item => item.Id).ToList();
PlayQueue.Reset(); PlayQueue.Reset();
PlayQueue.SetPlaylist(playlist); PlayQueue.SetPlaylist(playlist);
PlayQueue.SetPlayingItemById(session.FullNowPlayingItem.Id); PlayQueue.SetPlayingItemById(session.FullNowPlayingItem.Id);
@ -290,14 +281,13 @@ namespace Emby.Server.Implementations.SyncPlay
_state.SessionJoined(this, _state.Type, session, cancellationToken); _state.SessionJoined(this, _state.Type, session, cancellationToken);
_logger.LogInformation("InitGroup: {0} created group {1}.", session.Id, GroupId.ToString()); _logger.LogInformation("InitGroup: {SessionId} created group {GroupId}.", session.Id, GroupId.ToString());
} }
/// <inheritdoc /> /// <inheritdoc />
public void SessionJoin(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken) public void SessionJoin(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken)
{ {
AddSession(session); AddSession(session);
_syncPlayManager.AddSessionToGroup(session, this);
var updateSession = NewSyncPlayGroupUpdate(GroupUpdateType.GroupJoined, GetInfo()); var updateSession = NewSyncPlayGroupUpdate(GroupUpdateType.GroupJoined, GetInfo());
SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken); SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken);
@ -307,7 +297,7 @@ namespace Emby.Server.Implementations.SyncPlay
_state.SessionJoined(this, _state.Type, session, cancellationToken); _state.SessionJoined(this, _state.Type, session, cancellationToken);
_logger.LogInformation("SessionJoin: {0} joined group {1}.", session.Id, GroupId.ToString()); _logger.LogInformation("SessionJoin: {SessionId} joined group {GroupId}.", session.Id, GroupId.ToString());
} }
/// <inheritdoc /> /// <inheritdoc />
@ -321,7 +311,7 @@ namespace Emby.Server.Implementations.SyncPlay
_state.SessionJoined(this, _state.Type, session, cancellationToken); _state.SessionJoined(this, _state.Type, session, cancellationToken);
_logger.LogInformation("SessionRestore: {0} re-joined group {1}.", session.Id, GroupId.ToString()); _logger.LogInformation("SessionRestore: {SessionId} re-joined group {GroupId}.", session.Id, GroupId.ToString());
} }
/// <inheritdoc /> /// <inheritdoc />
@ -330,7 +320,6 @@ namespace Emby.Server.Implementations.SyncPlay
_state.SessionLeaving(this, _state.Type, session, cancellationToken); _state.SessionLeaving(this, _state.Type, session, cancellationToken);
RemoveSession(session); RemoveSession(session);
_syncPlayManager.RemoveSessionFromGroup(session, this);
var updateSession = NewSyncPlayGroupUpdate(GroupUpdateType.GroupLeft, GroupId.ToString()); var updateSession = NewSyncPlayGroupUpdate(GroupUpdateType.GroupLeft, GroupId.ToString());
SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken); SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken);
@ -338,7 +327,7 @@ namespace Emby.Server.Implementations.SyncPlay
var updateOthers = NewSyncPlayGroupUpdate(GroupUpdateType.UserLeft, session.UserName); var updateOthers = NewSyncPlayGroupUpdate(GroupUpdateType.UserLeft, session.UserName);
SendGroupUpdate(session, SyncPlayBroadcastType.AllExceptCurrentSession, updateOthers, cancellationToken); SendGroupUpdate(session, SyncPlayBroadcastType.AllExceptCurrentSession, updateOthers, cancellationToken);
_logger.LogInformation("SessionLeave: {0} left group {1}.", session.Id, GroupId.ToString()); _logger.LogInformation("SessionLeave: {SessionId} left group {GroupId}.", session.Id, GroupId.ToString());
} }
/// <inheritdoc /> /// <inheritdoc />
@ -347,27 +336,21 @@ namespace Emby.Server.Implementations.SyncPlay
// The server's job is to maintain a consistent state for clients to reference // The server's job is to maintain a consistent state for clients to reference
// and notify clients of state changes. The actual syncing of media playback // and notify clients of state changes. The actual syncing of media playback
// happens client side. Clients are aware of the server's time and use it to sync. // happens client side. Clients are aware of the server's time and use it to sync.
_logger.LogInformation("HandleRequest: {0} requested {1}, group {2} in {3} state.", session.Id, request.Type, GroupId.ToString(), _state.Type); _logger.LogInformation("HandleRequest: {SessionId} requested {RequestType}, group {GroupId} is {StateType}.", session.Id, request.Type, GroupId.ToString(), _state.Type);
request.Apply(this, _state, session, cancellationToken); request.Apply(this, _state, session, cancellationToken);
} }
/// <inheritdoc /> /// <inheritdoc />
public GroupInfoDto GetInfo() public GroupInfoDto GetInfo()
{ {
return new GroupInfoDto() var participants = Participants.Values.Select(session => session.Session.UserName).Distinct().ToList();
{ return new GroupInfoDto(GroupId, GroupName, _state.Type, participants, DateTime.UtcNow);
GroupId = GroupId.ToString(),
GroupName = GroupName,
State = _state.Type,
Participants = Participants.Values.Select(session => session.Session.UserName).Distinct().ToList(),
LastUpdatedAt = DateTime.UtcNow
};
} }
/// <inheritdoc /> /// <inheritdoc />
public bool HasAccessToPlayQueue(User user) public bool HasAccessToPlayQueue(User user)
{ {
var items = PlayQueue.GetPlaylist().Select(item => item.ItemId); var items = PlayQueue.GetPlaylist().Select(item => item.ItemId).ToList();
return HasAccessToQueue(user, items); return HasAccessToQueue(user, items);
} }
@ -383,7 +366,7 @@ namespace Emby.Server.Implementations.SyncPlay
/// <inheritdoc /> /// <inheritdoc />
public void SetState(IGroupState state) public void SetState(IGroupState state)
{ {
_logger.LogInformation("SetState: {0} switching from {1} to {2}.", GroupId.ToString(), _state.Type, state.Type); _logger.LogInformation("SetState: {GroupId} switching from {FromStateType} to {ToStateType}.", GroupId.ToString(), _state.Type, state.Type);
this._state = state; this._state = state;
} }
@ -418,26 +401,19 @@ namespace Emby.Server.Implementations.SyncPlay
/// <inheritdoc /> /// <inheritdoc />
public SendCommand NewSyncPlayCommand(SendCommandType type) public SendCommand NewSyncPlayCommand(SendCommandType type)
{ {
return new SendCommand() return new SendCommand(
{ GroupId,
GroupId = GroupId.ToString(), PlayQueue.GetPlayingItemPlaylistId(),
PlaylistItemId = PlayQueue.GetPlayingItemPlaylistId(), LastActivity,
PositionTicks = PositionTicks, type,
Command = type, PositionTicks,
When = LastActivity, DateTime.UtcNow);
EmittedAt = DateTime.UtcNow
};
} }
/// <inheritdoc /> /// <inheritdoc />
public GroupUpdate<T> NewSyncPlayGroupUpdate<T>(GroupUpdateType type, T data) public GroupUpdate<T> NewSyncPlayGroupUpdate<T>(GroupUpdateType type, T data)
{ {
return new GroupUpdate<T>() return new GroupUpdate<T>(GroupId, type, data);
{
GroupId = GroupId.ToString(),
Type = type,
Data = data
};
} }
/// <inheritdoc /> /// <inheritdoc />
@ -501,10 +477,10 @@ namespace Emby.Server.Implementations.SyncPlay
} }
/// <inheritdoc /> /// <inheritdoc />
public bool SetPlayQueue(IEnumerable<Guid> playQueue, int playingItemPosition, long startPositionTicks) public bool SetPlayQueue(IReadOnlyList<Guid> playQueue, int playingItemPosition, long startPositionTicks)
{ {
// Ignore on empty queue or invalid item position. // Ignore on empty queue or invalid item position.
if (!playQueue.Any() || playingItemPosition >= playQueue.Count() || playingItemPosition < 0) if (playQueue.Count == 0 || playingItemPosition >= playQueue.Count || playingItemPosition < 0)
{ {
return false; return false;
} }
@ -547,7 +523,7 @@ namespace Emby.Server.Implementations.SyncPlay
} }
/// <inheritdoc /> /// <inheritdoc />
public bool RemoveFromPlayQueue(IEnumerable<string> playlistItemIds) public bool RemoveFromPlayQueue(IReadOnlyList<string> playlistItemIds)
{ {
var playingItemRemoved = PlayQueue.RemoveFromPlaylist(playlistItemIds); var playingItemRemoved = PlayQueue.RemoveFromPlaylist(playlistItemIds);
if (playingItemRemoved) if (playingItemRemoved)
@ -576,10 +552,10 @@ namespace Emby.Server.Implementations.SyncPlay
} }
/// <inheritdoc /> /// <inheritdoc />
public bool AddToPlayQueue(IEnumerable<Guid> newItems, GroupQueueMode mode) public bool AddToPlayQueue(IReadOnlyList<Guid> newItems, GroupQueueMode mode)
{ {
// Ignore on empty list. // Ignore on empty list.
if (!newItems.Any()) if (newItems.Count == 0)
{ {
return false; return false;
} }
@ -673,16 +649,14 @@ namespace Emby.Server.Implementations.SyncPlay
startPositionTicks += Math.Max(elapsedTime.Ticks, 0); startPositionTicks += Math.Max(elapsedTime.Ticks, 0);
} }
return new PlayQueueUpdate() return new PlayQueueUpdate(
{ reason,
Reason = reason, PlayQueue.LastChange,
LastUpdate = PlayQueue.LastChange, PlayQueue.GetPlaylist(),
Playlist = PlayQueue.GetPlaylist(), PlayQueue.PlayingItemIndex,
PlayingItemIndex = PlayQueue.PlayingItemIndex, startPositionTicks,
StartPositionTicks = startPositionTicks, PlayQueue.ShuffleMode,
ShuffleMode = PlayQueue.ShuffleMode, PlayQueue.RepeatMode);
RepeatMode = PlayQueue.RepeatMode
};
} }
} }
} }

View File

@ -72,19 +72,9 @@ namespace Emby.Server.Implementations.SyncPlay
_userManager = userManager; _userManager = userManager;
_sessionManager = sessionManager; _sessionManager = sessionManager;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_sessionManager.SessionStarted += OnSessionManagerSessionStarted; _sessionManager.SessionStarted += OnSessionManagerSessionStarted;
_sessionManager.SessionEnded += OnSessionManagerSessionEnded;
_sessionManager.PlaybackStart += OnSessionManagerPlaybackStart;
_sessionManager.PlaybackStopped += OnSessionManagerPlaybackStopped;
} }
/// <summary>
/// Gets all groups.
/// </summary>
/// <value>All groups.</value>
public IEnumerable<IGroupController> Groups => _groups.Values;
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public void Dispose()
{ {
@ -92,127 +82,6 @@ namespace Emby.Server.Implementations.SyncPlay
GC.SuppressFinalize(this); 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;
}
_sessionManager.SessionStarted -= OnSessionManagerSessionStarted;
_sessionManager.SessionEnded -= OnSessionManagerSessionEnded;
_sessionManager.PlaybackStart -= OnSessionManagerPlaybackStart;
_sessionManager.PlaybackStopped -= OnSessionManagerPlaybackStopped;
_disposed = true;
}
private void OnSessionManagerSessionStarted(object sender, SessionEventArgs e)
{
var session = e.SessionInfo;
if (!IsSessionInGroup(session))
{
return;
}
var groupId = GetSessionGroup(session) ?? Guid.Empty;
var request = new JoinGroupRequest()
{
GroupId = groupId
};
JoinGroup(session, groupId, request, CancellationToken.None);
}
private void OnSessionManagerSessionEnded(object sender, SessionEventArgs e)
{
var session = e.SessionInfo;
if (!IsSessionInGroup(session))
{
return;
}
// TODO: probably remove this event, not used at the moment.
}
private void OnSessionManagerPlaybackStart(object sender, PlaybackProgressEventArgs e)
{
var session = e.Session;
if (!IsSessionInGroup(session))
{
return;
}
// TODO: probably remove this event, not used at the moment.
}
private void OnSessionManagerPlaybackStopped(object sender, PlaybackStopEventArgs e)
{
var session = e.Session;
if (!IsSessionInGroup(session))
{
return;
}
// TODO: probably remove this event, not used at the moment.
}
private bool IsRequestValid<T>(SessionInfo session, GroupRequestType requestType, T request, bool checkRequest = true)
{
if (session == null || (request == null && checkRequest))
{
return false;
}
var user = _userManager.GetUserById(session.UserId);
if (user.SyncPlayAccess == SyncPlayAccess.None)
{
_logger.LogWarning("IsRequestValid: {0} does not have access to SyncPlay. Requested {1}.", session.Id, requestType);
var error = new GroupUpdate<string>()
{
// TODO: rename to a more generic error. Next PR will fix this.
Type = GroupUpdateType.JoinGroupDenied
};
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
return false;
}
if (requestType.Equals(GroupRequestType.NewGroup) && user.SyncPlayAccess != SyncPlayAccess.CreateAndJoinGroups)
{
_logger.LogWarning("IsRequestValid: {0} does not have permission to create groups.", session.Id);
var error = new GroupUpdate<string>
{
Type = GroupUpdateType.CreateGroupDenied
};
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
return false;
}
return true;
}
private bool IsRequestValid(SessionInfo session, GroupRequestType requestType)
{
return IsRequestValid(session, requestType, session, false);
}
private bool IsSessionInGroup(SessionInfo session)
{
return _sessionToGroupMap.ContainsKey(session.Id);
}
private Guid? GetSessionGroup(SessionInfo session)
{
_sessionToGroupMap.TryGetValue(session.Id, out var group);
return group?.GroupId;
}
/// <inheritdoc /> /// <inheritdoc />
public void NewGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken) public void NewGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken)
{ {
@ -229,9 +98,10 @@ namespace Emby.Server.Implementations.SyncPlay
LeaveGroup(session, cancellationToken); LeaveGroup(session, cancellationToken);
} }
var group = new GroupController(_logger, _userManager, _sessionManager, _libraryManager, this); var group = new GroupController(_logger, _userManager, _sessionManager, _libraryManager);
_groups[group.GroupId] = group; _groups[group.GroupId] = group;
AddSessionToGroup(session, group);
group.CreateGroup(session, request, cancellationToken); group.CreateGroup(session, request, cancellationToken);
} }
} }
@ -253,25 +123,18 @@ namespace Emby.Server.Implementations.SyncPlay
if (group == null) if (group == null)
{ {
_logger.LogWarning("JoinGroup: {0} tried to join group {0} that does not exist.", session.Id, groupId); _logger.LogWarning("JoinGroup: {SessionId} tried to join group {GroupId} that does not exist.", session.Id, groupId);
var error = new GroupUpdate<string>() var error = new GroupUpdate<string>(Guid.Empty, GroupUpdateType.GroupDoesNotExist, string.Empty);
{
Type = GroupUpdateType.GroupDoesNotExist
};
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None); _sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
return; return;
} }
if (!group.HasAccessToPlayQueue(user)) if (!group.HasAccessToPlayQueue(user))
{ {
_logger.LogWarning("JoinGroup: {0} does not have access to some content from the playing queue of group {1}.", session.Id, group.GroupId.ToString()); _logger.LogWarning("JoinGroup: {SessionId} does not have access to some content from the playing queue of group {GroupId}.", session.Id, group.GroupId.ToString());
var error = new GroupUpdate<string>() var error = new GroupUpdate<string>(group.GroupId, GroupUpdateType.LibraryAccessDenied, string.Empty);
{
GroupId = group.GroupId.ToString(),
Type = GroupUpdateType.LibraryAccessDenied
};
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None); _sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
return; return;
} }
@ -287,6 +150,7 @@ namespace Emby.Server.Implementations.SyncPlay
LeaveGroup(session, cancellationToken); LeaveGroup(session, cancellationToken);
} }
AddSessionToGroup(session, group);
group.SessionJoin(session, request, cancellationToken); group.SessionJoin(session, request, cancellationToken);
} }
} }
@ -307,21 +171,19 @@ namespace Emby.Server.Implementations.SyncPlay
if (group == null) if (group == null)
{ {
_logger.LogWarning("LeaveGroup: {0} does not belong to any group.", session.Id); _logger.LogWarning("LeaveGroup: {SessionId} does not belong to any group.", session.Id);
var error = new GroupUpdate<string>() var error = new GroupUpdate<string>(Guid.Empty, GroupUpdateType.NotInGroup, string.Empty);
{
Type = GroupUpdateType.NotInGroup
};
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None); _sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
return; return;
} }
RemoveSessionFromGroup(session, group);
group.SessionLeave(session, cancellationToken); group.SessionLeave(session, cancellationToken);
if (group.IsGroupEmpty()) if (group.IsGroupEmpty())
{ {
_logger.LogInformation("LeaveGroup: removing empty group {0}.", group.GroupId); _logger.LogInformation("LeaveGroup: removing empty group {GroupId}.", group.GroupId);
_groups.Remove(group.GroupId, out _); _groups.Remove(group.GroupId, out _);
} }
} }
@ -338,11 +200,14 @@ namespace Emby.Server.Implementations.SyncPlay
var user = _userManager.GetUserById(session.UserId); var user = _userManager.GetUserById(session.UserId);
return _groups lock (_groupsLock)
.Values {
.Where(group => group.HasAccessToPlayQueue(user)) return _groups
.Select(group => group.GetInfo()) .Values
.ToList(); .Where(group => group.HasAccessToPlayQueue(user))
.Select(group => group.GetInfo())
.ToList();
}
} }
/// <inheritdoc /> /// <inheritdoc />
@ -360,12 +225,9 @@ namespace Emby.Server.Implementations.SyncPlay
if (group == null) if (group == null)
{ {
_logger.LogWarning("HandleRequest: {0} does not belong to any group.", session.Id); _logger.LogWarning("HandleRequest: {SessionId} does not belong to any group.", session.Id);
var error = new GroupUpdate<string>() var error = new GroupUpdate<string>(Guid.Empty, GroupUpdateType.NotInGroup, string.Empty);
{
Type = GroupUpdateType.NotInGroup
};
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None); _sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
return; return;
} }
@ -374,8 +236,74 @@ namespace Emby.Server.Implementations.SyncPlay
} }
} }
/// <inheritdoc /> /// <summary>
public void AddSessionToGroup(SessionInfo session, IGroupController group) /// 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;
}
_sessionManager.SessionStarted -= OnSessionManagerSessionStarted;
_disposed = true;
}
private void OnSessionManagerSessionStarted(object sender, SessionEventArgs e)
{
var session = e.SessionInfo;
lock (_groupsLock)
{
if (!IsSessionInGroup(session))
{
return;
}
var groupId = GetSessionGroup(session);
var request = new JoinGroupRequest(groupId);
JoinGroup(session, groupId, request, CancellationToken.None);
}
}
/// <summary>
/// Checks if a given session has joined a group.
/// </summary>
/// <remarks>
/// Not thread-safe, call only under groups-lock.
/// </remarks>
/// <param name="session">The session.</param>
/// <returns><c>true</c> if the session has joined a group, <c>false</c> otherwise.</returns>
private bool IsSessionInGroup(SessionInfo session)
{
return _sessionToGroupMap.ContainsKey(session.Id);
}
/// <summary>
/// Gets the group joined by the given session, if any.
/// </summary>
/// <remarks>
/// Not thread-safe, call only under groups-lock.
/// </remarks>
/// <param name="session">The session.</param>
/// <returns>The group identifier if the session has joined a group, an empty identifier otherwise.</returns>
private Guid GetSessionGroup(SessionInfo session)
{
_sessionToGroupMap.TryGetValue(session.Id, out var group);
return group?.GroupId ?? Guid.Empty;
}
/// <summary>
/// Maps a session to a group.
/// </summary>
/// <remarks>
/// Not thread-safe, call only under groups-lock.
/// </remarks>
/// <param name="session">The session.</param>
/// <param name="group">The group.</param>
/// <exception cref="InvalidOperationException">Thrown when the user is in another group already.</exception>
private void AddSessionToGroup(SessionInfo session, IGroupController group)
{ {
if (session == null) if (session == null)
{ {
@ -390,8 +318,16 @@ namespace Emby.Server.Implementations.SyncPlay
_sessionToGroupMap[session.Id] = group ?? throw new InvalidOperationException("Group is null!"); _sessionToGroupMap[session.Id] = group ?? throw new InvalidOperationException("Group is null!");
} }
/// <inheritdoc /> /// <summary>
public void RemoveSessionFromGroup(SessionInfo session, IGroupController group) /// Unmaps a session from a group.
/// </summary>
/// <remarks>
/// Not thread-safe, call only under groups-lock.
/// </remarks>
/// <param name="session">The session.</param>
/// <param name="group">The group.</param>
/// <exception cref="InvalidOperationException">Thrown when the user is not found in the specified group.</exception>
private void RemoveSessionFromGroup(SessionInfo session, IGroupController group)
{ {
if (session == null) if (session == null)
{ {
@ -414,5 +350,55 @@ namespace Emby.Server.Implementations.SyncPlay
throw new InvalidOperationException("Session was in wrong group!"); throw new InvalidOperationException("Session was in wrong group!");
} }
} }
/// <summary>
/// Checks if a given session is allowed to make a given request.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="requestType">The request type.</param>
/// <param name="request">The request.</param>
/// <param name="checkRequest">Whether to check if request is null.</param>
/// <returns><c>true</c> if the request is valid, <c>false</c> otherwise. Will return <c>false</c> also when session is null.</returns>
private bool IsRequestValid<T>(SessionInfo session, GroupRequestType requestType, T request, bool checkRequest = true)
{
if (session == null || (request == null && checkRequest))
{
return false;
}
var user = _userManager.GetUserById(session.UserId);
if (user.SyncPlayAccess == SyncPlayAccess.None)
{
_logger.LogWarning("IsRequestValid: {SessionId} does not have access to SyncPlay. Requested {RequestType}.", session.Id, requestType);
// TODO: rename to a more generic error. Next PR will fix this.
var error = new GroupUpdate<string>(Guid.Empty, GroupUpdateType.JoinGroupDenied, string.Empty);
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
return false;
}
if (requestType.Equals(GroupRequestType.NewGroup) && user.SyncPlayAccess != SyncPlayAccess.CreateAndJoinGroups)
{
_logger.LogWarning("IsRequestValid: {SessionId} does not have permission to create groups.", session.Id);
var error = new GroupUpdate<string>(Guid.Empty, GroupUpdateType.CreateGroupDenied, string.Empty);
_sessionManager.SendSyncPlayGroupUpdate(session, error, CancellationToken.None);
return false;
}
return true;
}
/// <summary>
/// Checks if a given session is allowed to make a given type of request.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="requestType">The request type.</param>
/// <returns><c>true</c> if the request is valid, <c>false</c> otherwise. Will return <c>false</c> also when session is null.</returns>
private bool IsRequestValid(SessionInfo session, GroupRequestType requestType)
{
return IsRequestValid(session, requestType, session, false);
}
} }
} }

View File

@ -53,10 +53,7 @@ namespace Jellyfin.Api.Controllers
[FromQuery, Required] string groupName) [FromQuery, Required] string groupName)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var newGroupRequest = new NewGroupRequest() var newGroupRequest = new NewGroupRequest(groupName);
{
GroupName = groupName
};
_syncPlayManager.NewGroup(currentSession, newGroupRequest, CancellationToken.None); _syncPlayManager.NewGroup(currentSession, newGroupRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -73,10 +70,7 @@ namespace Jellyfin.Api.Controllers
[FromQuery, Required] Guid groupId) [FromQuery, Required] Guid groupId)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var joinRequest = new JoinGroupRequest() var joinRequest = new JoinGroupRequest(groupId);
{
GroupId = groupId
};
_syncPlayManager.JoinGroup(currentSession, groupId, joinRequest, CancellationToken.None); _syncPlayManager.JoinGroup(currentSession, groupId, joinRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }
@ -185,18 +179,18 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Request to queue items to the playlist of a SyncPlay group. /// Request to queue items to the playlist of a SyncPlay group.
/// </summary> /// </summary>
/// <param name="items">The items to add.</param> /// <param name="itemIds">The items to add.</param>
/// <param name="mode">The mode in which to enqueue the items.</param> /// <param name="mode">The mode in which to enqueue the items.</param>
/// <response code="204">Queue update request sent to all group members.</response> /// <response code="204">Queue update request sent to all group members.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("Queue")] [HttpPost("Queue")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SyncPlayQueue( public ActionResult SyncPlayQueue(
[FromQuery, Required] Guid[] items, [FromQuery, Required] Guid[] itemIds,
[FromQuery, Required] GroupQueueMode mode) [FromQuery, Required] GroupQueueMode mode)
{ {
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request); var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new QueueGroupRequest(items, mode); var syncPlayRequest = new QueueGroupRequest(itemIds, mode);
_syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None);
return NoContent(); return NoContent();
} }

View File

@ -13,7 +13,7 @@ namespace Jellyfin.Api.Controllers
public class TimeSyncController : BaseJellyfinApiController public class TimeSyncController : BaseJellyfinApiController
{ {
/// <summary> /// <summary>
/// Gets the current utc time. /// Gets the current UTC time.
/// </summary> /// </summary>
/// <response code="200">Time returned.</response> /// <response code="200">Time returned.</response>
/// <returns>An <see cref="UtcTimeResponse"/> to sync the client and server time.</returns> /// <returns>An <see cref="UtcTimeResponse"/> to sync the client and server time.</returns>
@ -22,18 +22,14 @@ namespace Jellyfin.Api.Controllers
public ActionResult<UtcTimeResponse> GetUtcTime() public ActionResult<UtcTimeResponse> GetUtcTime()
{ {
// Important to keep the following line at the beginning // Important to keep the following line at the beginning
var requestReceptionTime = DateTime.UtcNow.ToUniversalTime().ToString("o", DateTimeFormatInfo.InvariantInfo); var requestReceptionTime = DateTime.UtcNow.ToUniversalTime();
var response = new UtcTimeResponse(); // Important to keep the following line at the end
response.RequestReceptionTime = requestReceptionTime; var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime();
// Important to keep the following two lines at the end
var responseTransmissionTime = DateTime.UtcNow.ToUniversalTime().ToString("o", DateTimeFormatInfo.InvariantInfo);
response.ResponseTransmissionTime = responseTransmissionTime;
// Implementing NTP on such a high level results in this useless // Implementing NTP on such a high level results in this useless
// information being sent. On the other hand it enables future additions. // information being sent. On the other hand it enables future additions.
return response; return new UtcTimeResponse(requestReceptionTime, responseTransmissionTime);
} }
} }
} }

View File

@ -68,7 +68,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
if (playingItemRemoved && !context.PlayQueue.IsItemPlaying()) if (playingItemRemoved && !context.PlayQueue.IsItemPlaying())
{ {
Logger.LogDebug("HandleRequest: {0} in group {1}, play queue is empty.", request.Type, context.GroupId.ToString()); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, play queue is empty.", request.Type, context.GroupId.ToString());
IGroupState idleState = new IdleGroupState(Logger); IGroupState idleState = new IdleGroupState(Logger);
context.SetState(idleState); context.SetState(idleState);
@ -84,7 +84,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
if (!result) if (!result)
{ {
Logger.LogError("HandleRequest: {0} in group {1}, unable to move item in play queue.", request.Type, context.GroupId.ToString()); Logger.LogError("HandleRequest: {RequestType} in group {GroupId}, unable to move item in play queue.", request.Type, context.GroupId.ToString());
return; return;
} }
@ -100,7 +100,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
if (!result) if (!result)
{ {
Logger.LogError("HandleRequest: {0} in group {1}, unable to add items to play queue.", request.Type, context.GroupId.ToString()); Logger.LogError("HandleRequest: {RequestType} in group {GroupId}, unable to add items to play queue.", request.Type, context.GroupId.ToString());
return; return;
} }
@ -203,18 +203,14 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
protected void SendGroupStateUpdate(IGroupStateContext context, IGroupPlaybackRequest reason, SessionInfo session, CancellationToken cancellationToken) protected void SendGroupStateUpdate(IGroupStateContext context, IGroupPlaybackRequest reason, SessionInfo session, CancellationToken cancellationToken)
{ {
// Notify relevant state change event. // Notify relevant state change event.
var stateUpdate = new GroupStateUpdate() var stateUpdate = new GroupStateUpdate(Type, reason.Type);
{
State = Type,
Reason = reason.Type
};
var update = context.NewSyncPlayGroupUpdate(GroupUpdateType.StateUpdate, stateUpdate); var update = context.NewSyncPlayGroupUpdate(GroupUpdateType.StateUpdate, stateUpdate);
context.SendGroupUpdate(session, SyncPlayBroadcastType.AllGroup, update, cancellationToken); context.SendGroupUpdate(session, SyncPlayBroadcastType.AllGroup, update, cancellationToken);
} }
private void UnhandledRequest(IGroupPlaybackRequest request) private void UnhandledRequest(IGroupPlaybackRequest request)
{ {
Logger.LogWarning("HandleRequest: unhandled {0} request for {1} state.", request.Type, Type); Logger.LogWarning("HandleRequest: unhandled {RequestType} request in {StateType} state.", request.Type, Type);
} }
} }
} }

View File

@ -103,7 +103,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
var unpauseRequest = new UnpauseGroupRequest(); var unpauseRequest = new UnpauseGroupRequest();
playingState.HandleRequest(context, Type, unpauseRequest, session, cancellationToken); playingState.HandleRequest(context, Type, unpauseRequest, session, cancellationToken);
Logger.LogDebug("SessionLeaving: {0} left the group {1}, notifying others to resume.", session.Id, context.GroupId.ToString()); Logger.LogDebug("SessionLeaving: {SessionId} left group {GroupId}, notifying others to resume.", session.Id, context.GroupId.ToString());
} }
else else
{ {
@ -111,7 +111,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
var pausedState = new PausedGroupState(Logger); var pausedState = new PausedGroupState(Logger);
context.SetState(pausedState); context.SetState(pausedState);
Logger.LogDebug("SessionLeaving: {0} left the group {1}, returning to previous state.", session.Id, context.GroupId.ToString()); Logger.LogDebug("SessionLeaving: {SessionId} left group {GroupId}, returning to previous state.", session.Id, context.GroupId.ToString());
} }
} }
} }
@ -131,7 +131,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
var setQueueStatus = context.SetPlayQueue(request.PlayingQueue, request.PlayingItemPosition, request.StartPositionTicks); var setQueueStatus = context.SetPlayQueue(request.PlayingQueue, request.PlayingItemPosition, request.StartPositionTicks);
if (!setQueueStatus) if (!setQueueStatus)
{ {
Logger.LogError("HandleRequest: {0} in group {1}, unable to set playing queue.", request.Type, context.GroupId.ToString()); Logger.LogError("HandleRequest: {RequestType} in group {GroupId}, unable to set playing queue.", request.Type, context.GroupId.ToString());
// Ignore request and return to previous state. // Ignore request and return to previous state.
IGroupState newState = prevState switch { IGroupState newState = prevState switch {
@ -151,7 +151,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
// Reset status of sessions and await for all Ready events. // Reset status of sessions and await for all Ready events.
context.SetAllBuffering(true); context.SetAllBuffering(true);
Logger.LogDebug("HandleRequest: {0} in group {1}, {2} set a new play queue.", request.Type, context.GroupId.ToString(), session.Id); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, {SessionId} set a new play queue.", request.Type, context.GroupId.ToString(), session.Id);
} }
/// <inheritdoc /> /// <inheritdoc />
@ -188,7 +188,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
context.SetState(newState); context.SetState(newState);
Logger.LogDebug("HandleRequest: {0} in group {1}, unable to change current playing item.", request.Type, context.GroupId.ToString()); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, unable to change current playing item.", request.Type, context.GroupId.ToString());
} }
} }
@ -214,13 +214,13 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
// Reset status of sessions and await for all Ready events. // Reset status of sessions and await for all Ready events.
context.SetAllBuffering(true); context.SetAllBuffering(true);
Logger.LogDebug("HandleRequest: {0} in group {1}, waiting for all ready events.", request.Type, context.GroupId.ToString()); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, waiting for all ready events.", request.Type, context.GroupId.ToString());
} }
else else
{ {
if (ResumePlaying) if (ResumePlaying)
{ {
Logger.LogDebug("HandleRequest: {0} in group {1}, ignoring sessions that are not ready and forcing the playback to start.", request.Type, context.GroupId.ToString()); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, ignoring sessions that are not ready and forcing the playback to start.", request.Type, context.GroupId.ToString());
// An Unpause request is forcing the playback to start, ignoring sessions that are not ready. // An Unpause request is forcing the playback to start, ignoring sessions that are not ready.
context.SetAllBuffering(false); context.SetAllBuffering(false);
@ -326,7 +326,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
// Make sure the client is playing the correct item. // Make sure the client is playing the correct item.
if (!request.PlaylistItemId.Equals(context.PlayQueue.GetPlayingItemPlaylistId(), StringComparison.OrdinalIgnoreCase)) if (!request.PlaylistItemId.Equals(context.PlayQueue.GetPlayingItemPlaylistId(), StringComparison.OrdinalIgnoreCase))
{ {
Logger.LogDebug("HandleRequest: {0} in group {1}, {2} has wrong playlist item.", request.Type, context.GroupId.ToString(), session.Id); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, {SessionId} has wrong playlist item.", request.Type, context.GroupId.ToString(), session.Id);
var playQueueUpdate = context.GetPlayQueueUpdate(PlayQueueUpdateReason.SetCurrentItem); var playQueueUpdate = context.GetPlayQueueUpdate(PlayQueueUpdateReason.SetCurrentItem);
var updateSession = context.NewSyncPlayGroupUpdate(GroupUpdateType.PlayQueue, playQueueUpdate); var updateSession = context.NewSyncPlayGroupUpdate(GroupUpdateType.PlayQueue, playQueueUpdate);
@ -400,7 +400,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
// Make sure the client is playing the correct item. // Make sure the client is playing the correct item.
if (!request.PlaylistItemId.Equals(context.PlayQueue.GetPlayingItemPlaylistId(), StringComparison.OrdinalIgnoreCase)) if (!request.PlaylistItemId.Equals(context.PlayQueue.GetPlayingItemPlaylistId(), StringComparison.OrdinalIgnoreCase))
{ {
Logger.LogDebug("HandleRequest: {0} in group {1}, {2} has wrong playlist item.", request.Type, context.GroupId.ToString(), session.Id); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, {SessionId} has wrong playlist item.", request.Type, context.GroupId.ToString(), session.Id);
var playQueueUpdate = context.GetPlayQueueUpdate(PlayQueueUpdateReason.SetCurrentItem); var playQueueUpdate = context.GetPlayQueueUpdate(PlayQueueUpdateReason.SetCurrentItem);
var update = context.NewSyncPlayGroupUpdate(GroupUpdateType.PlayQueue, playQueueUpdate); var update = context.NewSyncPlayGroupUpdate(GroupUpdateType.PlayQueue, playQueueUpdate);
@ -420,7 +420,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
var timeSyncThresholdTicks = TimeSpan.FromMilliseconds(context.TimeSyncOffset).Ticks; var timeSyncThresholdTicks = TimeSpan.FromMilliseconds(context.TimeSyncOffset).Ticks;
if (Math.Abs(elapsedTime.Ticks) > timeSyncThresholdTicks) if (Math.Abs(elapsedTime.Ticks) > timeSyncThresholdTicks)
{ {
Logger.LogWarning("HandleRequest: {0} in group {1}, {2} is not time syncing properly. Ignoring elapsed time.", request.Type, context.GroupId.ToString(), session.Id); Logger.LogWarning("HandleRequest: {RequestType} in group {GroupId}, {SessionId} is not time syncing properly. Ignoring elapsed time.", request.Type, context.GroupId.ToString(), session.Id);
elapsedTime = TimeSpan.Zero; elapsedTime = TimeSpan.Zero;
} }
@ -436,7 +436,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
var delayTicks = context.PositionTicks - clientPosition.Ticks; var delayTicks = context.PositionTicks - clientPosition.Ticks;
var maxPlaybackOffsetTicks = TimeSpan.FromMilliseconds(context.MaxPlaybackOffset).Ticks; var maxPlaybackOffsetTicks = TimeSpan.FromMilliseconds(context.MaxPlaybackOffset).Ticks;
Logger.LogDebug("HandleRequest: {0} in group {1}, {2} at {3} (delay of {4} seconds).", request.Type, context.GroupId.ToString(), session.Id, clientPosition, TimeSpan.FromTicks(delayTicks).TotalSeconds); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, {SessionId} at {PositionTicks} (delay of {Delay} seconds).", request.Type, context.GroupId.ToString(), session.Id, clientPosition, TimeSpan.FromTicks(delayTicks).TotalSeconds);
if (ResumePlaying) if (ResumePlaying)
{ {
@ -454,7 +454,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
// Notify relevant state change event. // Notify relevant state change event.
SendGroupStateUpdate(context, request, session, cancellationToken); SendGroupStateUpdate(context, request, session, cancellationToken);
Logger.LogWarning("HandleRequest: {0} in group {1}, {2} got lost in time, correcting.", request.Type, context.GroupId.ToString(), session.Id); Logger.LogWarning("HandleRequest: {RequestType} in group {GroupId}, {SessionId} got lost in time, correcting.", request.Type, context.GroupId.ToString(), session.Id);
return; return;
} }
@ -468,7 +468,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
command.When = currentTime.AddTicks(delayTicks); command.When = currentTime.AddTicks(delayTicks);
context.SendCommand(session, SyncPlayBroadcastType.CurrentSession, command, cancellationToken); context.SendCommand(session, SyncPlayBroadcastType.CurrentSession, command, cancellationToken);
Logger.LogInformation("HandleRequest: {0} in group {1}, others still buffering, {2} will pause when ready in {3} seconds.", request.Type, context.GroupId.ToString(), session.Id, TimeSpan.FromTicks(delayTicks).TotalSeconds); Logger.LogInformation("HandleRequest: {RequestType} in group {GroupId}, others still buffering, {SessionId} will pause when ready in {Delay} seconds.", request.Type, context.GroupId.ToString(), session.Id, TimeSpan.FromTicks(delayTicks).TotalSeconds);
} }
else else
{ {
@ -487,7 +487,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
context.SendCommand(session, filter, command, cancellationToken); context.SendCommand(session, filter, command, cancellationToken);
Logger.LogInformation("HandleRequest: {0} in group {1}, {2} is recovering, notifying others to resume in {3} seconds.", request.Type, context.GroupId.ToString(), session.Id, TimeSpan.FromTicks(delayTicks).TotalSeconds); Logger.LogInformation("HandleRequest: {RequestType} in group {GroupId}, {SessionId} is recovering, notifying others to resume in {Delay} seconds.", request.Type, context.GroupId.ToString(), session.Id, TimeSpan.FromTicks(delayTicks).TotalSeconds);
} }
else else
{ {
@ -500,7 +500,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
var command = context.NewSyncPlayCommand(SendCommandType.Unpause); var command = context.NewSyncPlayCommand(SendCommandType.Unpause);
context.SendCommand(session, SyncPlayBroadcastType.AllGroup, command, cancellationToken); context.SendCommand(session, SyncPlayBroadcastType.AllGroup, command, cancellationToken);
Logger.LogWarning("HandleRequest: {0} in group {1}, {2} resumed playback but did not update others in time. {3} seconds to recover.", request.Type, context.GroupId.ToString(), session.Id, TimeSpan.FromTicks(delayTicks).TotalSeconds); Logger.LogWarning("HandleRequest: {RequestType} in group {GroupId}, {SessionId} resumed playback but did not update others in time. {Delay} seconds to recover.", request.Type, context.GroupId.ToString(), session.Id, TimeSpan.FromTicks(delayTicks).TotalSeconds);
} }
// Change state. // Change state.
@ -511,7 +511,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
} }
else else
{ {
// Check that session is really ready, tollerate player imperfections under a certain threshold. // Check that session is really ready, tolerate player imperfections under a certain threshold.
if (Math.Abs(context.PositionTicks - requestTicks) > maxPlaybackOffsetTicks) if (Math.Abs(context.PositionTicks - requestTicks) > maxPlaybackOffsetTicks)
{ {
// Session still not ready. // Session still not ready.
@ -523,7 +523,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
// Notify relevant state change event. // Notify relevant state change event.
SendGroupStateUpdate(context, request, session, cancellationToken); SendGroupStateUpdate(context, request, session, cancellationToken);
Logger.LogWarning("HandleRequest: {0} in group {1}, {2} was seeking to wrong position, correcting.", request.Type, context.GroupId.ToString(), session.Id); Logger.LogWarning("HandleRequest: {RequestType} in group {GroupId}, {SessionId} is seeking to wrong position, correcting.", request.Type, context.GroupId.ToString(), session.Id);
return; return;
} }
else else
@ -549,7 +549,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
pausedState.HandleRequest(context, Type, request, session, cancellationToken); pausedState.HandleRequest(context, Type, request, session, cancellationToken);
} }
Logger.LogDebug("HandleRequest: {0} in group {1}, {2} is ready, returning to previous state.", request.Type, context.GroupId.ToString(), session.Id); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, {SessionId} is ready, returning to previous state.", request.Type, context.GroupId.ToString(), session.Id);
} }
} }
} }
@ -569,7 +569,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
// Make sure the client knows the playing item, to avoid duplicate requests. // Make sure the client knows the playing item, to avoid duplicate requests.
if (!request.PlaylistItemId.Equals(context.PlayQueue.GetPlayingItemPlaylistId(), StringComparison.OrdinalIgnoreCase)) if (!request.PlaylistItemId.Equals(context.PlayQueue.GetPlayingItemPlaylistId(), StringComparison.OrdinalIgnoreCase))
{ {
Logger.LogDebug("HandleRequest: {0} in group {1}, client provided the wrong playlist identifier.", request.Type, context.GroupId.ToString()); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, {SessionId} provided the wrong playlist identifier.", request.Type, context.GroupId.ToString(), session.Id);
return; return;
} }
@ -596,7 +596,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
context.SetState(newState); context.SetState(newState);
Logger.LogDebug("HandleRequest: {0} in group {1}, no next track available.", request.Type, context.GroupId.ToString()); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, no next track available.", request.Type, context.GroupId.ToString());
} }
} }
@ -615,7 +615,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
// Make sure the client knows the playing item, to avoid duplicate requests. // Make sure the client knows the playing item, to avoid duplicate requests.
if (!request.PlaylistItemId.Equals(context.PlayQueue.GetPlayingItemPlaylistId(), StringComparison.OrdinalIgnoreCase)) if (!request.PlaylistItemId.Equals(context.PlayQueue.GetPlayingItemPlaylistId(), StringComparison.OrdinalIgnoreCase))
{ {
Logger.LogDebug("HandleRequest: {0} in group {1}, client provided the wrong playlist identifier.", request.Type, context.GroupId.ToString()); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, {SessionId} provided the wrong playlist identifier.", request.Type, context.GroupId.ToString(), session.Id);
return; return;
} }
@ -642,7 +642,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
context.SetState(newState); context.SetState(newState);
Logger.LogDebug("HandleRequest: {0} in group {1}, no previous track available.", request.Type, context.GroupId.ToString()); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, no previous track available.", request.Type, context.GroupId.ToString());
} }
} }
@ -653,7 +653,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
if (!context.IsBuffering()) if (!context.IsBuffering())
{ {
Logger.LogDebug("HandleRequest: {0} in group {1}, returning to previous state.", request.Type, context.GroupId.ToString()); Logger.LogDebug("HandleRequest: {RequestType} in group {GroupId}, returning to previous state.", request.Type, context.GroupId.ToString());
if (ResumePlaying) if (ResumePlaying)
{ {

View File

@ -151,7 +151,7 @@ namespace MediaBrowser.Controller.SyncPlay
/// <param name="playingItemPosition">The playing item position in the play queue.</param> /// <param name="playingItemPosition">The playing item position in the play queue.</param>
/// <param name="startPositionTicks">The start position ticks.</param> /// <param name="startPositionTicks">The start position ticks.</param>
/// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns> /// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns>
bool SetPlayQueue(IEnumerable<Guid> playQueue, int playingItemPosition, long startPositionTicks); bool SetPlayQueue(IReadOnlyList<Guid> playQueue, int playingItemPosition, long startPositionTicks);
/// <summary> /// <summary>
/// Sets the playing item. /// Sets the playing item.
@ -165,7 +165,7 @@ namespace MediaBrowser.Controller.SyncPlay
/// </summary> /// </summary>
/// <param name="playlistItemIds">The items to remove.</param> /// <param name="playlistItemIds">The items to remove.</param>
/// <returns><c>true</c> if playing item got removed; <c>false</c> otherwise.</returns> /// <returns><c>true</c> if playing item got removed; <c>false</c> otherwise.</returns>
bool RemoveFromPlayQueue(IEnumerable<string> playlistItemIds); bool RemoveFromPlayQueue(IReadOnlyList<string> playlistItemIds);
/// <summary> /// <summary>
/// Moves an item in the play queue. /// Moves an item in the play queue.
@ -181,7 +181,7 @@ namespace MediaBrowser.Controller.SyncPlay
/// <param name="newItems">The new items to add to the play queue.</param> /// <param name="newItems">The new items to add to the play queue.</param>
/// <param name="mode">The mode with which the items will be added.</param> /// <param name="mode">The mode with which the items will be added.</param>
/// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns> /// <returns><c>true</c> if the play queue has been changed; <c>false</c> if something went wrong.</returns>
bool AddToPlayQueue(IEnumerable<Guid> newItems, GroupQueueMode mode); bool AddToPlayQueue(IReadOnlyList<Guid> newItems, GroupQueueMode mode);
/// <summary> /// <summary>
/// Restarts current item in play queue. /// Restarts current item in play queue.

View File

@ -49,21 +49,5 @@ namespace MediaBrowser.Controller.SyncPlay
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
void HandleRequest(SessionInfo session, IGroupPlaybackRequest request, CancellationToken cancellationToken); void HandleRequest(SessionInfo session, IGroupPlaybackRequest request, CancellationToken cancellationToken);
/// <summary>
/// Maps a session to a group.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="group">The group.</param>
/// <exception cref="InvalidOperationException">Thrown when the user is in another group already.</exception>
void AddSessionToGroup(SessionInfo session, IGroupController group);
/// <summary>
/// Unmaps a session from a group.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="group">The group.</param>
/// <exception cref="InvalidOperationException">Thrown when the user is not found in the specified group.</exception>
void RemoveSessionFromGroup(SessionInfo session, IGroupController group);
} }
} }

View File

@ -19,9 +19,7 @@ namespace MediaBrowser.Controller.SyncPlay.PlaybackRequests
/// <param name="startPositionTicks">The start position ticks.</param> /// <param name="startPositionTicks">The start position ticks.</param>
public PlayGroupRequest(Guid[] playingQueue, int playingItemPosition, long startPositionTicks) public PlayGroupRequest(Guid[] playingQueue, int playingItemPosition, long startPositionTicks)
{ {
var list = new List<Guid>(); PlayingQueue = playingQueue ?? Array.Empty<Guid>();
list.AddRange(playingQueue);
PlayingQueue = list;
PlayingItemPosition = playingItemPosition; PlayingItemPosition = playingItemPosition;
StartPositionTicks = startPositionTicks; StartPositionTicks = startPositionTicks;
} }

View File

@ -18,9 +18,7 @@ namespace MediaBrowser.Controller.SyncPlay.PlaybackRequests
/// <param name="mode">The enqueue mode.</param> /// <param name="mode">The enqueue mode.</param>
public QueueGroupRequest(Guid[] items, GroupQueueMode mode) public QueueGroupRequest(Guid[] items, GroupQueueMode mode)
{ {
var list = new List<Guid>(); ItemIds = items ?? Array.Empty<Guid>();
list.AddRange(items);
ItemIds = list;
Mode = mode; Mode = mode;
} }

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
@ -16,9 +17,7 @@ namespace MediaBrowser.Controller.SyncPlay.PlaybackRequests
/// <param name="items">The playlist ids of the items to remove.</param> /// <param name="items">The playlist ids of the items to remove.</param>
public RemoveFromPlaylistGroupRequest(string[] items) public RemoveFromPlaylistGroupRequest(string[] items)
{ {
var list = new List<string>(); PlaylistItemIds = items ?? Array.Empty<string>();
list.AddRange(items);
PlaylistItemIds = list;
} }
/// <summary> /// <summary>

View File

@ -94,7 +94,7 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
/// Sets a new playlist. Playing item is reset. /// Sets a new playlist. Playing item is reset.
/// </summary> /// </summary>
/// <param name="items">The new items of the playlist.</param> /// <param name="items">The new items of the playlist.</param>
public void SetPlaylist(IEnumerable<Guid> items) public void SetPlaylist(IReadOnlyList<Guid> items)
{ {
SortedPlaylist.Clear(); SortedPlaylist.Clear();
ShuffledPlaylist.Clear(); ShuffledPlaylist.Clear();
@ -114,7 +114,7 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
/// Appends new items to the playlist. The specified order is mantained. /// Appends new items to the playlist. The specified order is mantained.
/// </summary> /// </summary>
/// <param name="items">The items to add to the playlist.</param> /// <param name="items">The items to add to the playlist.</param>
public void Queue(IEnumerable<Guid> items) public void Queue(IReadOnlyList<Guid> items)
{ {
var newItems = CreateQueueItemsFromArray(items); var newItems = CreateQueueItemsFromArray(items);
@ -209,7 +209,7 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
/// Adds new items to the playlist right after the playing item. The specified order is mantained. /// Adds new items to the playlist right after the playing item. The specified order is mantained.
/// </summary> /// </summary>
/// <param name="items">The items to add to the playlist.</param> /// <param name="items">The items to add to the playlist.</param>
public void QueueNext(IEnumerable<Guid> items) public void QueueNext(IReadOnlyList<Guid> items)
{ {
var newItems = CreateQueueItemsFromArray(items); var newItems = CreateQueueItemsFromArray(items);
@ -312,13 +312,12 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
/// </summary> /// </summary>
/// <param name="playlistItemIds">The items to remove.</param> /// <param name="playlistItemIds">The items to remove.</param>
/// <returns><c>true</c> if playing item got removed; <c>false</c> otherwise.</returns> /// <returns><c>true</c> if playing item got removed; <c>false</c> otherwise.</returns>
public bool RemoveFromPlaylist(IEnumerable<string> playlistItemIds) public bool RemoveFromPlaylist(IReadOnlyList<string> playlistItemIds)
{ {
var playingItem = GetPlayingItem(); var playingItem = GetPlayingItem();
var playlistItemIdsList = playlistItemIds.ToList();
SortedPlaylist.RemoveAll(item => playlistItemIdsList.Contains(item.PlaylistItemId)); SortedPlaylist.RemoveAll(item => playlistItemIds.Contains(item.PlaylistItemId));
ShuffledPlaylist.RemoveAll(item => playlistItemIdsList.Contains(item.PlaylistItemId)); ShuffledPlaylist.RemoveAll(item => playlistItemIds.Contains(item.PlaylistItemId));
LastChange = DateTime.UtcNow; LastChange = DateTime.UtcNow;
@ -369,8 +368,7 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
var queueItem = playlist[oldIndex]; var queueItem = playlist[oldIndex];
playlist.RemoveAt(oldIndex); playlist.RemoveAt(oldIndex);
newIndex = Math.Min(newIndex, playlist.Count); newIndex = Math.Clamp(newIndex, 0, playlist.Count);
newIndex = Math.Max(newIndex, 0);
playlist.Insert(newIndex, queueItem); playlist.Insert(newIndex, queueItem);
LastChange = DateTime.UtcNow; LastChange = DateTime.UtcNow;
@ -489,7 +487,7 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
} }
else else
{ {
PlayingItemIndex--; PlayingItemIndex = SortedPlaylist.Count - 1;
return false; return false;
} }
} }
@ -519,7 +517,7 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
} }
else else
{ {
PlayingItemIndex++; PlayingItemIndex = 0;
return false; return false;
} }
} }
@ -558,7 +556,7 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
/// Creates a list from the array of items. Each item is given an unique playlist identifier. /// Creates a list from the array of items. Each item is given an unique playlist identifier.
/// </summary> /// </summary>
/// <returns>The list of queue items.</returns> /// <returns>The list of queue items.</returns>
private List<QueueItem> CreateQueueItemsFromArray(IEnumerable<Guid> items) private List<QueueItem> CreateQueueItemsFromArray(IReadOnlyList<Guid> items)
{ {
var list = new List<QueueItem>(); var list = new List<QueueItem>();
foreach (var item in items) foreach (var item in items)

View File

@ -11,41 +11,48 @@ namespace MediaBrowser.Model.SyncPlay
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GroupInfoDto"/> class. /// Initializes a new instance of the <see cref="GroupInfoDto"/> class.
/// </summary> /// </summary>
public GroupInfoDto() /// <param name="groupId">The group identifier.</param>
/// <param name="groupName">The group name.</param>
/// <param name="state">The group state.</param>
/// <param name="participants">The participants.</param>
/// <param name="lastUpdatedAt">The date when this DTO has been created.</param>
public GroupInfoDto(Guid groupId, string groupName, GroupStateType state, IReadOnlyList<string> participants, DateTime lastUpdatedAt)
{ {
GroupId = string.Empty; GroupId = groupId;
GroupName = string.Empty; GroupName = groupName;
Participants = new List<string>(); State = state;
Participants = participants;
LastUpdatedAt = lastUpdatedAt;
} }
/// <summary> /// <summary>
/// Gets or sets the group identifier. /// Gets the group identifier.
/// </summary> /// </summary>
/// <value>The group identifier.</value> /// <value>The group identifier.</value>
public string GroupId { get; set; } public Guid GroupId { get; }
/// <summary> /// <summary>
/// Gets or sets the group name. /// Gets the group name.
/// </summary> /// </summary>
/// <value>The group name.</value> /// <value>The group name.</value>
public string GroupName { get; set; } public string GroupName { get; }
/// <summary> /// <summary>
/// Gets or sets the group state. /// Gets the group state.
/// </summary> /// </summary>
/// <value>The group state.</value> /// <value>The group state.</value>
public GroupStateType State { get; set; } public GroupStateType State { get; }
/// <summary> /// <summary>
/// Gets or sets the participants. /// Gets the participants.
/// </summary> /// </summary>
/// <value>The participants.</value> /// <value>The participants.</value>
public IReadOnlyList<string> Participants { get; set; } public IReadOnlyList<string> Participants { get; }
/// <summary> /// <summary>
/// Gets or sets the date when this dto has been updated. /// Gets the date when this DTO has been created.
/// </summary> /// </summary>
/// <value>The date when this dto has been updated.</value> /// <value>The date when this DTO has been created.</value>
public DateTime LastUpdatedAt { get; set; } public DateTime LastUpdatedAt { get; }
} }
} }

View File

@ -6,15 +6,26 @@ namespace MediaBrowser.Model.SyncPlay
public class GroupStateUpdate public class GroupStateUpdate
{ {
/// <summary> /// <summary>
/// Gets or sets the state of the group. /// Initializes a new instance of the <see cref="GroupStateUpdate"/> class.
/// </summary> /// </summary>
/// <value>The state of the group.</value> /// <param name="state">The state of the group.</param>
public GroupStateType State { get; set; } /// <param name="reason">The reason of the state change.</param>
public GroupStateUpdate(GroupStateType state, PlaybackRequestType reason)
{
State = state;
Reason = reason;
}
/// <summary> /// <summary>
/// Gets or sets the reason of the state change. /// Gets the state of the group.
/// </summary>
/// <value>The state of the group.</value>
public GroupStateType State { get; }
/// <summary>
/// Gets the reason of the state change.
/// </summary> /// </summary>
/// <value>The reason of the state change.</value> /// <value>The reason of the state change.</value>
public PlaybackRequestType Reason { get; set; } public PlaybackRequestType Reason { get; }
} }
} }

View File

@ -1,4 +1,4 @@
#nullable disable using System;
namespace MediaBrowser.Model.SyncPlay namespace MediaBrowser.Model.SyncPlay
{ {
@ -9,21 +9,34 @@ namespace MediaBrowser.Model.SyncPlay
public class GroupUpdate<T> public class GroupUpdate<T>
{ {
/// <summary> /// <summary>
/// Gets or sets the group identifier. /// Initializes a new instance of the <see cref="GroupUpdate{T}"/> class.
/// </summary>
/// <param name="groupId">The group identifier.</param>
/// <param name="type">The update type.</param>
/// <param name="data">The update data.</param>
public GroupUpdate(Guid groupId, GroupUpdateType type, T data)
{
GroupId = groupId;
Type = type;
Data = data;
}
/// <summary>
/// Gets the group identifier.
/// </summary> /// </summary>
/// <value>The group identifier.</value> /// <value>The group identifier.</value>
public string GroupId { get; set; } public Guid GroupId { get; }
/// <summary> /// <summary>
/// Gets or sets the update type. /// Gets the update type.
/// </summary> /// </summary>
/// <value>The update type.</value> /// <value>The update type.</value>
public GroupUpdateType Type { get; set; } public GroupUpdateType Type { get; }
/// <summary> /// <summary>
/// Gets or sets the data. /// Gets the update data.
/// </summary> /// </summary>
/// <value>The data.</value> /// <value>The update data.</value>
public T Data { get; set; } public T Data { get; }
} }
} }

View File

@ -8,9 +8,18 @@ namespace MediaBrowser.Model.SyncPlay
public class JoinGroupRequest public class JoinGroupRequest
{ {
/// <summary> /// <summary>
/// Gets or sets the group identifier. /// Initializes a new instance of the <see cref="JoinGroupRequest"/> class.
/// </summary>
/// <param name="groupId">The identifier of the group to join.</param>
public JoinGroupRequest(Guid groupId)
{
GroupId = groupId;
}
/// <summary>
/// Gets the group identifier.
/// </summary> /// </summary>
/// <value>The identifier of the group to join.</value> /// <value>The identifier of the group to join.</value>
public Guid GroupId { get; set; } public Guid GroupId { get; }
} }
} }

View File

@ -8,15 +8,16 @@ namespace MediaBrowser.Model.SyncPlay
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="NewGroupRequest"/> class. /// Initializes a new instance of the <see cref="NewGroupRequest"/> class.
/// </summary> /// </summary>
public NewGroupRequest() /// <param name="groupName">The name of the new group.</param>
public NewGroupRequest(string groupName)
{ {
GroupName = string.Empty; GroupName = groupName;
} }
/// <summary> /// <summary>
/// Gets or sets the group name. /// Gets the group name.
/// </summary> /// </summary>
/// <value>The name of the new group.</value> /// <value>The name of the new group.</value>
public string GroupName { get; set; } public string GroupName { get; }
} }
} }

View File

@ -11,51 +11,64 @@ namespace MediaBrowser.Model.SyncPlay
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PlayQueueUpdate"/> class. /// Initializes a new instance of the <see cref="PlayQueueUpdate"/> class.
/// </summary> /// </summary>
public PlayQueueUpdate() /// <param name="reason">The reason for the update.</param>
/// <param name="lastUpdate">The UTC time of the last change to the playing queue.</param>
/// <param name="playlist">The playlist.</param>
/// <param name="playingItemIndex">The playing item index in the playlist.</param>
/// <param name="startPositionTicks">The start position ticks.</param>
/// <param name="shuffleMode">The shuffle mode.</param>
/// <param name="repeatMode">The repeat mode.</param>
public PlayQueueUpdate(PlayQueueUpdateReason reason, DateTime lastUpdate, IReadOnlyList<QueueItem> playlist, int playingItemIndex, long startPositionTicks, GroupShuffleMode shuffleMode, GroupRepeatMode repeatMode)
{ {
Playlist = new List<QueueItem>(); Reason = reason;
LastUpdate = lastUpdate;
Playlist = playlist;
PlayingItemIndex = playingItemIndex;
StartPositionTicks = startPositionTicks;
ShuffleMode = shuffleMode;
RepeatMode = repeatMode;
} }
/// <summary> /// <summary>
/// Gets or sets the request type that originated this update. /// Gets the request type that originated this update.
/// </summary> /// </summary>
/// <value>The reason for the update.</value> /// <value>The reason for the update.</value>
public PlayQueueUpdateReason Reason { get; set; } public PlayQueueUpdateReason Reason { get; }
/// <summary> /// <summary>
/// Gets or sets the UTC time of the last change to the playing queue. /// Gets the UTC time of the last change to the playing queue.
/// </summary> /// </summary>
/// <value>The UTC time of the last change to the playing queue.</value> /// <value>The UTC time of the last change to the playing queue.</value>
public DateTime LastUpdate { get; set; } public DateTime LastUpdate { get; }
/// <summary> /// <summary>
/// Gets or sets the playlist. /// Gets the playlist.
/// </summary> /// </summary>
/// <value>The playlist.</value> /// <value>The playlist.</value>
public IReadOnlyList<QueueItem> Playlist { get; set; } public IReadOnlyList<QueueItem> Playlist { get; }
/// <summary> /// <summary>
/// Gets or sets the playing item index in the playlist. /// Gets the playing item index in the playlist.
/// </summary> /// </summary>
/// <value>The playing item index in the playlist.</value> /// <value>The playing item index in the playlist.</value>
public int PlayingItemIndex { get; set; } public int PlayingItemIndex { get; }
/// <summary> /// <summary>
/// Gets or sets the start position ticks. /// Gets the start position ticks.
/// </summary> /// </summary>
/// <value>The start position ticks.</value> /// <value>The start position ticks.</value>
public long StartPositionTicks { get; set; } public long StartPositionTicks { get; }
/// <summary> /// <summary>
/// Gets or sets the shuffle mode. /// Gets the shuffle mode.
/// </summary> /// </summary>
/// <value>The shuffle mode.</value> /// <value>The shuffle mode.</value>
public GroupShuffleMode ShuffleMode { get; set; } public GroupShuffleMode ShuffleMode { get; }
/// <summary> /// <summary>
/// Gets or sets the repeat mode. /// Gets the repeat mode.
/// </summary> /// </summary>
/// <value>The repeat mode.</value> /// <value>The repeat mode.</value>
public GroupRepeatMode RepeatMode { get; set; } public GroupRepeatMode RepeatMode { get; }
} }
} }

View File

@ -10,23 +10,33 @@ namespace MediaBrowser.Model.SyncPlay
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SendCommand"/> class. /// Initializes a new instance of the <see cref="SendCommand"/> class.
/// </summary> /// </summary>
public SendCommand() /// <param name="groupId">The group identifier.</param>
/// <param name="playlistItemId">The playlist identifier of the playing item.</param>
/// <param name="when">The UTC time when to execute the command.</param>
/// <param name="command">The command.</param>
/// <param name="positionTicks">The position ticks, for commands that require it.</param>
/// <param name="emittedAt">The UTC time when this command has been emitted.</param>
public SendCommand(Guid groupId, string playlistItemId, DateTime when, SendCommandType command, long? positionTicks, DateTime emittedAt)
{ {
GroupId = string.Empty; GroupId = groupId;
PlaylistItemId = string.Empty; PlaylistItemId = playlistItemId;
When = when;
Command = command;
PositionTicks = positionTicks;
EmittedAt = emittedAt;
} }
/// <summary> /// <summary>
/// Gets or sets the group identifier. /// Gets the group identifier.
/// </summary> /// </summary>
/// <value>The group identifier.</value> /// <value>The group identifier.</value>
public string GroupId { get; set; } public Guid GroupId { get; }
/// <summary> /// <summary>
/// Gets or sets the playlist identifier of the playing item. /// Gets the playlist identifier of the playing item.
/// </summary> /// </summary>
/// <value>The playlist identifier of the playing item.</value> /// <value>The playlist identifier of the playing item.</value>
public string PlaylistItemId { get; set; } public string PlaylistItemId { get; }
/// <summary> /// <summary>
/// Gets or sets the UTC time when to execute the command. /// Gets or sets the UTC time when to execute the command.
@ -35,21 +45,21 @@ namespace MediaBrowser.Model.SyncPlay
public DateTime When { get; set; } public DateTime When { get; set; }
/// <summary> /// <summary>
/// Gets or sets the position ticks. /// Gets the position ticks.
/// </summary> /// </summary>
/// <value>The position ticks.</value> /// <value>The position ticks.</value>
public long? PositionTicks { get; set; } public long? PositionTicks { get; }
/// <summary> /// <summary>
/// Gets or sets the command. /// Gets the command.
/// </summary> /// </summary>
/// <value>The command.</value> /// <value>The command.</value>
public SendCommandType Command { get; set; } public SendCommandType Command { get; }
/// <summary> /// <summary>
/// Gets or sets the UTC time when this command has been emitted. /// Gets the UTC time when this command has been emitted.
/// </summary> /// </summary>
/// <value>The UTC time when this command has been emitted.</value> /// <value>The UTC time when this command has been emitted.</value>
public DateTime EmittedAt { get; set; } public DateTime EmittedAt { get; }
} }
} }

View File

@ -1,4 +1,4 @@
#nullable disable using System;
namespace MediaBrowser.Model.SyncPlay namespace MediaBrowser.Model.SyncPlay
{ {
@ -8,15 +8,26 @@ namespace MediaBrowser.Model.SyncPlay
public class UtcTimeResponse public class UtcTimeResponse
{ {
/// <summary> /// <summary>
/// Gets or sets the UTC time when request has been received. /// Initializes a new instance of the <see cref="UtcTimeResponse"/> class.
/// </summary> /// </summary>
/// <value>The UTC time when request has been received.</value> /// <param name="requestReceptionTime">The UTC time when request has been received.</param>
public string RequestReceptionTime { get; set; } /// <param name="responseTransmissionTime">The UTC time when response has been sent.</param>
public UtcTimeResponse(DateTime requestReceptionTime, DateTime responseTransmissionTime)
{
RequestReceptionTime = requestReceptionTime;
ResponseTransmissionTime = responseTransmissionTime;
}
/// <summary> /// <summary>
/// Gets or sets the UTC time when response has been sent. /// Gets the UTC time when request has been received.
/// </summary>
/// <value>The UTC time when request has been received.</value>
public DateTime RequestReceptionTime { get; }
/// <summary>
/// Gets the UTC time when response has been sent.
/// </summary> /// </summary>
/// <value>The UTC time when response has been sent.</value> /// <value>The UTC time when response has been sent.</value>
public string ResponseTransmissionTime { get; set; } public DateTime ResponseTransmissionTime { get; }
} }
} }