Refactor: rename user to session

This commit is contained in:
gion
2020-04-04 17:56:21 +02:00
parent b3354ec637
commit f273995f5b
5 changed files with 169 additions and 169 deletions

View File

@@ -12,7 +12,7 @@ namespace MediaBrowser.Controller.Syncplay
public class GroupInfo
{
/// <summary>
/// Default ping value used for users.
/// Default ping value used for sessions.
/// </summary>
public readonly long DefaulPing = 500;
/// <summary>
@@ -53,85 +53,85 @@ namespace MediaBrowser.Controller.Syncplay
new ConcurrentDictionary<string, GroupMember>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Checks if a user is in this group.
/// Checks if a session is in this group.
/// </summary>
/// <value><c>true</c> if the user is in this group; <c>false</c> otherwise.</value>
public bool ContainsUser(string sessionId)
/// <value><c>true</c> if the session is in this group; <c>false</c> otherwise.</value>
public bool ContainsSession(string sessionId)
{
return Partecipants.ContainsKey(sessionId);
}
/// <summary>
/// Adds the user to the group.
/// Adds the session to the group.
/// </summary>
/// <param name="user">The session.</param>
public void AddUser(SessionInfo user)
/// <param name="session">The session.</param>
public void AddSession(SessionInfo session)
{
if (ContainsUser(user.Id.ToString())) return;
if (ContainsSession(session.Id.ToString())) return;
var member = new GroupMember();
member.Session = user;
member.Session = session;
member.Ping = DefaulPing;
member.IsBuffering = false;
Partecipants[user.Id.ToString()] = member;
Partecipants[session.Id.ToString()] = member;
}
/// <summary>
/// Removes the user from the group.
/// Removes the session from the group.
/// </summary>
/// <param name="user">The session.</param>
/// <param name="session">The session.</param>
public void RemoveUser(SessionInfo user)
public void RemoveSession(SessionInfo session)
{
if (!ContainsUser(user.Id.ToString())) return;
if (!ContainsSession(session.Id.ToString())) return;
GroupMember member;
Partecipants.Remove(user.Id.ToString(), out member);
Partecipants.Remove(session.Id.ToString(), out member);
}
/// <summary>
/// Updates the ping of a user.
/// Updates the ping of a session.
/// </summary>
/// <param name="user">The session.</param>
/// <param name="session">The session.</param>
/// <param name="ping">The ping.</param>
public void UpdatePing(SessionInfo user, long ping)
public void UpdatePing(SessionInfo session, long ping)
{
if (!ContainsUser(user.Id.ToString())) return;
Partecipants[user.Id.ToString()].Ping = ping;
if (!ContainsSession(session.Id.ToString())) return;
Partecipants[session.Id.ToString()].Ping = ping;
}
/// <summary>
/// Gets the highest ping in the group.
/// </summary>
/// <value name="user">The highest ping in the group.</value>
/// <value name="session">The highest ping in the group.</value>
public long GetHighestPing()
{
long max = Int64.MinValue;
foreach (var user in Partecipants.Values)
foreach (var session in Partecipants.Values)
{
max = Math.Max(max, user.Ping);
max = Math.Max(max, session.Ping);
}
return max;
}
/// <summary>
/// Sets the user's buffering state.
/// Sets the session's buffering state.
/// </summary>
/// <param name="user">The session.</param>
/// <param name="session">The session.</param>
/// <param name="isBuffering">The state.</param>
public void SetBuffering(SessionInfo user, bool isBuffering)
public void SetBuffering(SessionInfo session, bool isBuffering)
{
if (!ContainsUser(user.Id.ToString())) return;
Partecipants[user.Id.ToString()].IsBuffering = isBuffering;
if (!ContainsSession(session.Id.ToString())) return;
Partecipants[session.Id.ToString()].IsBuffering = isBuffering;
}
/// <summary>
/// Gets the group buffering state.
/// </summary>
/// <value><c>true</c> if there is a user buffering in the group; <c>false</c> otherwise.</value>
/// <value><c>true</c> if there is a session buffering in the group; <c>false</c> otherwise.</value>
public bool IsBuffering()
{
foreach (var user in Partecipants.Values)
foreach (var session in Partecipants.Values)
{
if (user.IsBuffering) return true;
if (session.IsBuffering) return true;
}
return false;
}

View File

@@ -28,29 +28,29 @@ namespace MediaBrowser.Controller.Syncplay
bool IsGroupEmpty();
/// <summary>
/// Initializes the group with the user's info.
/// Initializes the group with the session's info.
/// </summary>
/// <param name="user">The session.</param>
void InitGroup(SessionInfo user);
/// <param name="session">The session.</param>
void InitGroup(SessionInfo session);
/// <summary>
/// Adds the user to the group.
/// Adds the session to the group.
/// </summary>
/// <param name="user">The session.</param>
void UserJoin(SessionInfo user);
/// <param name="session">The session.</param>
void SessionJoin(SessionInfo session);
/// <summary>
/// Removes the user from the group.
/// Removes the session from the group.
/// </summary>
/// <param name="user">The session.</param>
void UserLeave(SessionInfo user);
/// <param name="session">The session.</param>
void SessionLeave(SessionInfo session);
/// <summary>
/// Handles the requested action by the user.
/// Handles the requested action by the session.
/// </summary>
/// <param name="user">The session.</param>
/// <param name="session">The session.</param>
/// <param name="request">The requested action.</param>
void HandleRequest(SessionInfo user, SyncplayRequestInfo request);
void HandleRequest(SessionInfo session, SyncplayRequestInfo request);
/// <summary>
/// Gets the info about the group for the clients.

View File

@@ -13,50 +13,50 @@ namespace MediaBrowser.Controller.Syncplay
/// <summary>
/// Creates a new group.
/// </summary>
/// <param name="user">The user that's creating the group.</param>
void NewGroup(SessionInfo user);
/// <param name="session">The session that's creating the group.</param>
void NewGroup(SessionInfo session);
/// <summary>
/// Adds the user to a group.
/// Adds the session to a group.
/// </summary>
/// <param name="user">The session.</param>
/// <param name="session">The session.</param>
/// <param name="groupId">The group id.</param>
void JoinGroup(SessionInfo user, string groupId);
void JoinGroup(SessionInfo session, string groupId);
/// <summary>
/// Removes the user from a group.
/// Removes the session from a group.
/// </summary>
/// <param name="user">The session.</param>
void LeaveGroup(SessionInfo user);
/// <param name="session">The session.</param>
void LeaveGroup(SessionInfo session);
/// <summary>
/// Gets list of available groups for a user.
/// Gets list of available groups for a session.
/// </summary>
/// <param name="user">The user.</param>
/// <param name="session">The session.</param>
/// <value>The list of available groups.</value>
List<GroupInfoView> ListGroups(SessionInfo user);
List<GroupInfoView> ListGroups(SessionInfo session);
/// <summary>
/// Handle a request by a user in a group.
/// Handle a request by a session in a group.
/// </summary>
/// <param name="user">The session.</param>
/// <param name="session">The session.</param>
/// <param name="request">The request.</param>
void HandleRequest(SessionInfo user, SyncplayRequestInfo request);
void HandleRequest(SessionInfo session, SyncplayRequestInfo request);
/// <summary>
/// Maps a user to a group.
/// Maps a session to a group.
/// </summary>
/// <param name="user">The user.</param>
/// <param name="session">The session.</param>
/// <param name="group">The group.</param>
/// <exception cref="InvalidOperationException"></exception>
void MapUserToGroup(SessionInfo user, ISyncplayController group);
void MapSessionToGroup(SessionInfo session, ISyncplayController group);
/// <summary>
/// Unmaps a user from a group.
/// Unmaps a session from a group.
/// </summary>
/// <param name="user">The user.</param>
/// <param name="session">The session.</param>
/// <param name="group">The group.</param>
/// <exception cref="InvalidOperationException"></exception>
void UnmapUserFromGroup(SessionInfo user, ISyncplayController group);
void UnmapSessionFromGroup(SessionInfo session, ISyncplayController group);
}
}