|
|
@ -25,8 +25,8 @@ namespace MediaBrowser.Server.Implementations.Library
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// The _active connections
|
|
|
|
/// The _active connections
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private readonly List<ClientConnectionInfo> _activeConnections =
|
|
|
|
private readonly ConcurrentDictionary<string, ClientConnectionInfo> _activeConnections =
|
|
|
|
new List<ClientConnectionInfo>();
|
|
|
|
new ConcurrentDictionary<string, ClientConnectionInfo>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// The _users
|
|
|
|
/// The _users
|
|
|
@ -69,7 +69,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|
|
|
/// <value>All connections.</value>
|
|
|
|
/// <value>All connections.</value>
|
|
|
|
public IEnumerable<ClientConnectionInfo> AllConnections
|
|
|
|
public IEnumerable<ClientConnectionInfo> AllConnections
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get { return _activeConnections.Where(c => GetUserById(c.UserId) != null).OrderByDescending(c => c.LastActivityDate); }
|
|
|
|
get { return _activeConnections.Values.OrderByDescending(c => c.LastActivityDate); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -313,29 +313,19 @@ namespace MediaBrowser.Server.Implementations.Library
|
|
|
|
/// <returns>ClientConnectionInfo.</returns>
|
|
|
|
/// <returns>ClientConnectionInfo.</returns>
|
|
|
|
private ClientConnectionInfo GetConnection(Guid userId, string clientType, string deviceId, string deviceName)
|
|
|
|
private ClientConnectionInfo GetConnection(Guid userId, string clientType, string deviceId, string deviceName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock (_activeConnections)
|
|
|
|
var key = clientType + deviceId;
|
|
|
|
{
|
|
|
|
|
|
|
|
var conn = _activeConnections.FirstOrDefault(c => string.Equals(c.Client, clientType, StringComparison.OrdinalIgnoreCase) && string.Equals(deviceId, c.DeviceId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conn == null)
|
|
|
|
var connection = _activeConnections.GetOrAdd(key, keyName => new ClientConnectionInfo
|
|
|
|
{
|
|
|
|
|
|
|
|
conn = new ClientConnectionInfo
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UserId = userId,
|
|
|
|
UserId = userId,
|
|
|
|
Client = clientType,
|
|
|
|
Client = clientType,
|
|
|
|
DeviceName = deviceName,
|
|
|
|
DeviceName = deviceName,
|
|
|
|
DeviceId = deviceId
|
|
|
|
DeviceId = deviceId
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
_activeConnections.Add(conn);
|
|
|
|
connection.UserId = userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
conn.UserId = userId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return conn;
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|