Send error messages to clients

This commit is contained in:
gion 2020-04-22 22:05:53 +02:00
parent 083d3272d0
commit 73fcbe90c0
2 changed files with 75 additions and 27 deletions

View File

@ -165,8 +165,14 @@ namespace Emby.Server.Implementations.Syncplay
if (user.Policy.SyncplayAccess != SyncplayAccess.CreateAndJoinGroups) if (user.Policy.SyncplayAccess != SyncplayAccess.CreateAndJoinGroups)
{ {
// TODO: report the error to the client _logger.LogWarning("Syncplaymanager NewGroup: {0} does not have permission to create groups.", session.Id);
throw new ArgumentException("User does not have permission to create groups");
var error = new GroupUpdate<string>()
{
Type = GroupUpdateType.CreateGroupDenied
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
} }
if (IsSessionInGroup(session)) if (IsSessionInGroup(session))
@ -187,8 +193,14 @@ namespace Emby.Server.Implementations.Syncplay
if (user.Policy.SyncplayAccess == SyncplayAccess.None) if (user.Policy.SyncplayAccess == SyncplayAccess.None)
{ {
// TODO: report the error to the client _logger.LogWarning("Syncplaymanager JoinGroup: {0} does not have access to Syncplay.", session.Id);
throw new ArgumentException("User does not have access to syncplay");
var error = new GroupUpdate<string>()
{
Type = GroupUpdateType.JoinGroupDenied
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
} }
ISyncplayController group; ISyncplayController group;
@ -196,17 +208,27 @@ namespace Emby.Server.Implementations.Syncplay
if (group == null) if (group == null)
{ {
_logger.LogWarning("Syncplaymanager JoinGroup: {0} does not exist.", groupId); _logger.LogWarning("Syncplaymanager JoinGroup: {0} tried to join group {0} that does not exist.", session.Id, groupId);
var update = new GroupUpdate<string>(); var error = new GroupUpdate<string>()
update.Type = GroupUpdateType.NotInGroup; {
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), update, CancellationToken.None); Type = GroupUpdateType.GroupNotJoined
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return; return;
} }
if (!HasAccessToItem(user, group.GetPlayingItemId())) if (!HasAccessToItem(user, group.GetPlayingItemId()))
{ {
throw new ArgumentException("User does not have access to playing item"); _logger.LogWarning("Syncplaymanager JoinGroup: {0} does not have access to {1}.", session.Id, group.GetPlayingItemId());
var error = new GroupUpdate<string>()
{
GroupId = group.GetGroupId().ToString(),
Type = GroupUpdateType.LibraryAccessDenied
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
} }
if (IsSessionInGroup(session)) if (IsSessionInGroup(session))
@ -230,9 +252,11 @@ namespace Emby.Server.Implementations.Syncplay
{ {
_logger.LogWarning("Syncplaymanager LeaveGroup: {0} does not belong to any group.", session.Id); _logger.LogWarning("Syncplaymanager LeaveGroup: {0} does not belong to any group.", session.Id);
var update = new GroupUpdate<string>(); var error = new GroupUpdate<string>()
update.Type = GroupUpdateType.NotInGroup; {
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), update, CancellationToken.None); Type = GroupUpdateType.NotInGroup
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return; return;
} }
group.SessionLeave(session); group.SessionLeave(session);
@ -280,8 +304,14 @@ namespace Emby.Server.Implementations.Syncplay
if (user.Policy.SyncplayAccess == SyncplayAccess.None) if (user.Policy.SyncplayAccess == SyncplayAccess.None)
{ {
// TODO: same as LeaveGroup _logger.LogWarning("Syncplaymanager HandleRequest: {0} does not have access to Syncplay.", session.Id);
throw new ArgumentException("User does not have access to syncplay");
var error = new GroupUpdate<string>()
{
Type = GroupUpdateType.JoinGroupDenied
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
} }
ISyncplayController group; ISyncplayController group;
@ -289,11 +319,13 @@ namespace Emby.Server.Implementations.Syncplay
if (group == null) if (group == null)
{ {
_logger.LogWarning("Syncplaymanager HandleRequest: {0} not in a group.", session.Id); _logger.LogWarning("Syncplaymanager HandleRequest: {0} does not belong to any group.", session.Id);
var update = new GroupUpdate<string>(); var error = new GroupUpdate<string>()
update.Type = GroupUpdateType.NotInGroup; {
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), update, CancellationToken.None); Type = GroupUpdateType.NotInGroup
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return; return;
} }
group.HandleRequest(session, request); group.HandleRequest(session, request);

View File

@ -1,37 +1,53 @@
namespace MediaBrowser.Model.Syncplay namespace MediaBrowser.Model.Syncplay
{ {
/// <summary> /// <summary>
/// Enum GroupUpdateType /// Enum GroupUpdateType.
/// </summary> /// </summary>
public enum GroupUpdateType public enum GroupUpdateType
{ {
/// <summary> /// <summary>
/// The user-joined update. Tells members of a group about a new user. /// The user-joined update. Tells members of a group about a new user.
/// </summary> /// </summary>
UserJoined = 0, UserJoined,
/// <summary> /// <summary>
/// The user-left update. Tells members of a group that a user left. /// The user-left update. Tells members of a group that a user left.
/// </summary> /// </summary>
UserLeft = 1, UserLeft,
/// <summary> /// <summary>
/// The group-joined update. Tells a user that the group has been joined. /// The group-joined update. Tells a user that the group has been joined.
/// </summary> /// </summary>
GroupJoined = 2, GroupJoined,
/// <summary> /// <summary>
/// The group-left update. Tells a user that the group has been left. /// The group-left update. Tells a user that the group has been left.
/// </summary> /// </summary>
GroupLeft = 3, GroupLeft,
/// <summary> /// <summary>
/// The group-wait update. Tells members of the group that a user is buffering. /// The group-wait update. Tells members of the group that a user is buffering.
/// </summary> /// </summary>
GroupWait = 4, GroupWait,
/// <summary> /// <summary>
/// The prepare-session update. Tells a user to load some content. /// The prepare-session update. Tells a user to load some content.
/// </summary> /// </summary>
PrepareSession = 5, PrepareSession,
/// <summary> /// <summary>
/// The not-in-group update. Tells a user that no group has been joined. /// The not-in-group error. Tells a user that it doesn't belong to a group.
/// </summary> /// </summary>
NotInGroup = 7 NotInGroup,
/// <summary>
/// The group-not-joined error. Sent when a request to join a group fails.
/// </summary>
GroupNotJoined,
/// <summary>
/// The create-group-denied error. Sent when a user tries to create a group without required permissions.
/// </summary>
CreateGroupDenied,
/// <summary>
/// The join-group-denied error. Sent when a user tries to join a group without required permissions.
/// </summary>
JoinGroupDenied,
/// <summary>
/// The library-access-denied error. Sent when a user tries to join a group without required access to the library.
/// </summary>
LibraryAccessDenied
} }
} }