mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-23 14:10:40 +02:00
added session disposal
This commit is contained in:
parent
8b534cc34a
commit
e657a1cdab
|
@ -69,6 +69,8 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
private IEnumerable<ISessionControllerFactory> _sessionFactories = new List<ISessionControllerFactory>();
|
||||
|
||||
private readonly SemaphoreSlim _sessionLock = new SemaphoreSlim(1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SessionManager" /> class.
|
||||
/// </summary>
|
||||
|
@ -146,7 +148,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
var userId = user == null ? (Guid?)null : user.Id;
|
||||
var username = user == null ? null : user.Name;
|
||||
|
||||
var session = GetSessionInfo(clientType, appVersion, deviceId, deviceName, remoteEndPoint, userId, username);
|
||||
var session = await GetSessionInfo(clientType, appVersion, deviceId, deviceName, remoteEndPoint, userId, username).ConfigureAwait(false);
|
||||
|
||||
session.LastActivityDate = activityDate;
|
||||
|
||||
|
@ -171,6 +173,46 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
return session;
|
||||
}
|
||||
|
||||
public async Task ReportSessionEnded(Guid sessionId)
|
||||
{
|
||||
var session = GetSession(sessionId);
|
||||
|
||||
if (session == null)
|
||||
{
|
||||
throw new ArgumentException("Session not found");
|
||||
}
|
||||
|
||||
var key = GetSessionKey(session.Client, session.ApplicationVersion, session.DeviceId);
|
||||
|
||||
await _sessionLock.WaitAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
SessionInfo removed;
|
||||
|
||||
if (_activeConnections.TryRemove(key, out removed))
|
||||
{
|
||||
var disposable = removed.SessionController as IDisposable;
|
||||
|
||||
if (disposable != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error disposing session controller", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_sessionLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the now playing item id.
|
||||
/// </summary>
|
||||
|
@ -207,6 +249,11 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
}
|
||||
}
|
||||
|
||||
private string GetSessionKey(string clientType, string appVersion, string deviceId)
|
||||
{
|
||||
return clientType + deviceId + appVersion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the connection.
|
||||
/// </summary>
|
||||
|
@ -218,10 +265,14 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
/// <param name="userId">The user identifier.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <returns>SessionInfo.</returns>
|
||||
private SessionInfo GetSessionInfo(string clientType, string appVersion, string deviceId, string deviceName, string remoteEndPoint, Guid? userId, string username)
|
||||
private async Task<SessionInfo> GetSessionInfo(string clientType, string appVersion, string deviceId, string deviceName, string remoteEndPoint, Guid? userId, string username)
|
||||
{
|
||||
var key = clientType + deviceId + appVersion;
|
||||
var key = GetSessionKey(clientType, appVersion, deviceId);
|
||||
|
||||
await _sessionLock.WaitAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
var connection = _activeConnections.GetOrAdd(key, keyName => new SessionInfo
|
||||
{
|
||||
Client = clientType,
|
||||
|
@ -249,6 +300,11 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
return connection;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_sessionLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private List<User> GetUsers(SessionInfo session)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue