diff options
Diffstat (limited to 'Emby.Server.Implementations/Session/SessionManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Session/SessionManager.cs | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index ab860ef67..7f927e270 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -329,13 +329,17 @@ namespace Emby.Server.Implementations.Session } /// <inheritdoc /> - public void CloseIfNeeded(SessionInfo session) + public async Task CloseIfNeededAsync(SessionInfo session) { if (!session.SessionControllers.Any(i => i.IsSessionActive)) { var key = GetSessionKey(session.Client, session.DeviceId); _activeConnections.TryRemove(key, out _); + if (!string.IsNullOrEmpty(session.PlayState?.LiveStreamId)) + { + await _mediaSourceManager.CloseLiveStream(session.PlayState.LiveStreamId).ConfigureAwait(false); + } OnSessionEnded(session); } @@ -373,7 +377,7 @@ namespace Emby.Server.Implementations.Session info.MediaSourceId = info.ItemId.ToString("N", CultureInfo.InvariantCulture); } - if (!info.ItemId.Equals(Guid.Empty) && info.Item == null && libraryItem != null) + if (!info.ItemId.Equals(default) && info.Item == null && libraryItem != null) { var current = session.NowPlayingItem; @@ -413,6 +417,7 @@ namespace Emby.Server.Implementations.Session session.PlayState.IsPaused = info.IsPaused; session.PlayState.PositionTicks = info.PositionTicks; session.PlayState.MediaSourceId = info.MediaSourceId; + session.PlayState.LiveStreamId = info.LiveStreamId; session.PlayState.CanSeek = info.CanSeek; session.PlayState.IsMuted = info.IsMuted; session.PlayState.VolumeLevel = info.VolumeLevel; @@ -558,22 +563,24 @@ namespace Emby.Server.Implementations.Session { var users = new List<User>(); - if (session.UserId != Guid.Empty) + if (session.UserId.Equals(default)) { - var user = _userManager.GetUserById(session.UserId); - - if (user == null) - { - throw new InvalidOperationException("User not found"); - } + return users; + } - users.Add(user); + var user = _userManager.GetUserById(session.UserId); - users.AddRange(session.AdditionalUsers - .Select(i => _userManager.GetUserById(i.UserId)) - .Where(i => i != null)); + if (user == null) + { + throw new InvalidOperationException("User not found"); } + users.Add(user); + + users.AddRange(session.AdditionalUsers + .Select(i => _userManager.GetUserById(i.UserId)) + .Where(i => i != null)); + return users; } @@ -665,7 +672,7 @@ namespace Emby.Server.Implementations.Session var session = GetSession(info.SessionId); - var libraryItem = info.ItemId == Guid.Empty + var libraryItem = info.ItemId.Equals(default) ? null : GetNowPlayingItem(session, info.ItemId); @@ -697,7 +704,9 @@ namespace Emby.Server.Implementations.Session DeviceName = session.DeviceName, ClientName = session.Client, DeviceId = session.DeviceId, - Session = session + Session = session, + PlaybackPositionTicks = info.PositionTicks, + PlaySessionId = info.PlaySessionId }; await _eventManager.PublishAsync(eventArgs).ConfigureAwait(false); @@ -760,12 +769,17 @@ namespace Emby.Server.Implementations.Session var session = GetSession(info.SessionId); - var libraryItem = info.ItemId.Equals(Guid.Empty) + var libraryItem = info.ItemId.Equals(default) ? null : GetNowPlayingItem(session, info.ItemId); await UpdateNowPlayingItem(session, info, libraryItem, !isAutomated).ConfigureAwait(false); + if (!string.IsNullOrEmpty(session.DeviceId) && info.PlayMethod != PlayMethod.Transcode) + { + ClearTranscodingInfo(session.DeviceId); + } + var users = GetUsers(session); // only update saved user data on actual check-ins, not automated ones @@ -897,7 +911,7 @@ namespace Emby.Server.Implementations.Session session.StopAutomaticProgress(); - var libraryItem = info.ItemId.Equals(Guid.Empty) + var libraryItem = info.ItemId.Equals(default) ? null : GetNowPlayingItem(session, info.ItemId); @@ -907,7 +921,7 @@ namespace Emby.Server.Implementations.Session info.MediaSourceId = info.ItemId.ToString("N", CultureInfo.InvariantCulture); } - if (!info.ItemId.Equals(Guid.Empty) && info.Item == null && libraryItem != null) + if (!info.ItemId.Equals(default) && info.Item == null && libraryItem != null) { var current = session.NowPlayingItem; @@ -983,7 +997,8 @@ namespace Emby.Server.Implementations.Session DeviceName = session.DeviceName, ClientName = session.Client, DeviceId = session.DeviceId, - Session = session + Session = session, + PlaySessionId = info.PlaySessionId }; await _eventManager.PublishAsync(eventArgs).ConfigureAwait(false); @@ -1127,7 +1142,7 @@ namespace Emby.Server.Implementations.Session var session = GetSessionToRemoteControl(sessionId); - var user = session.UserId == Guid.Empty ? null : _userManager.GetUserById(session.UserId); + var user = session.UserId.Equals(default) ? null : _userManager.GetUserById(session.UserId); List<BaseItem> items; @@ -1182,7 +1197,7 @@ namespace Emby.Server.Implementations.Session EnableImages = false }) .Where(i => !i.IsVirtualItem) - .SkipWhile(i => i.Id != episode.Id) + .SkipWhile(i => !i.Id.Equals(episode.Id)) .ToList(); if (episodes.Count > 0) @@ -1196,7 +1211,7 @@ namespace Emby.Server.Implementations.Session { var controllingSession = GetSession(controllingSessionId); AssertCanControl(session, controllingSession); - if (!controllingSession.UserId.Equals(Guid.Empty)) + if (!controllingSession.UserId.Equals(default)) { command.ControllingUserId = controllingSession.UserId; } @@ -1227,7 +1242,7 @@ namespace Emby.Server.Implementations.Session if (item == null) { - _logger.LogError("A non-existant item Id {0} was passed into TranslateItemForPlayback", id); + _logger.LogError("A non-existent item Id {0} was passed into TranslateItemForPlayback", id); return Array.Empty<BaseItem>(); } @@ -1315,7 +1330,7 @@ namespace Emby.Server.Implementations.Session { var controllingSession = GetSession(controllingSessionId); AssertCanControl(session, controllingSession); - if (!controllingSession.UserId.Equals(Guid.Empty)) + if (!controllingSession.UserId.Equals(default)) { command.ControllingUserId = controllingSession.UserId.ToString("N", CultureInfo.InvariantCulture); } @@ -1388,12 +1403,12 @@ namespace Emby.Server.Implementations.Session var session = GetSession(sessionId); - if (session.UserId == userId) + if (session.UserId.Equals(userId)) { throw new ArgumentException("The requested user is already the primary user of the session."); } - if (session.AdditionalUsers.All(i => i.UserId != userId)) + if (session.AdditionalUsers.All(i => !i.UserId.Equals(userId))) { var user = _userManager.GetUserById(userId); @@ -1463,7 +1478,7 @@ namespace Emby.Server.Implementations.Session CheckDisposed(); User user = null; - if (request.UserId != Guid.Empty) + if (!request.UserId.Equals(default)) { user = _userManager.GetUserById(request.UserId); } @@ -1792,7 +1807,7 @@ namespace Emby.Server.Implementations.Session throw new ArgumentNullException(nameof(info)); } - var user = info.UserId == Guid.Empty + var user = info.UserId.Equals(default) ? null : _userManager.GetUserById(info.UserId); |
