From 8a6b26cd424adb9537e14fd5ef833de9dd7dd4de Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Fri, 27 May 2022 15:57:51 -0600 Subject: [PATCH 1/3] initial patch --- Emby.Server.Implementations/Session/SessionManager.cs | 1 + MediaBrowser.Model/Session/PlayerStateInfo.cs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index d08fedd111..8c8d088b6a 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -413,6 +413,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; diff --git a/MediaBrowser.Model/Session/PlayerStateInfo.cs b/MediaBrowser.Model/Session/PlayerStateInfo.cs index 0f10605ea1..80e6d4e0b0 100644 --- a/MediaBrowser.Model/Session/PlayerStateInfo.cs +++ b/MediaBrowser.Model/Session/PlayerStateInfo.cs @@ -64,5 +64,11 @@ namespace MediaBrowser.Model.Session /// /// The repeat mode. public RepeatMode RepeatMode { get; set; } + + /// + /// Gets or sets the now playing live stream identifier. + /// + /// The live stream identifier. + public string LiveStreamId { get; set; } } } From bf0a7c374c9277bcf71e000c68e22a9c24c41744 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Fri, 27 May 2022 15:58:31 -0600 Subject: [PATCH 2/3] Close live stream on session end --- Emby.Server.Implementations/Session/SessionManager.cs | 6 +++++- Emby.Server.Implementations/Session/WebSocketController.cs | 4 ++-- MediaBrowser.Controller/Session/ISessionManager.cs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index 8c8d088b6a..eaf2c25daf 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -329,13 +329,17 @@ namespace Emby.Server.Implementations.Session } /// - 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); } diff --git a/Emby.Server.Implementations/Session/WebSocketController.cs b/Emby.Server.Implementations/Session/WebSocketController.cs index 9fa92a53a1..d21b6a929c 100644 --- a/Emby.Server.Implementations/Session/WebSocketController.cs +++ b/Emby.Server.Implementations/Session/WebSocketController.cs @@ -53,13 +53,13 @@ namespace Emby.Server.Implementations.Session connection.Closed += OnConnectionClosed; } - private void OnConnectionClosed(object? sender, EventArgs e) + private async void OnConnectionClosed(object? sender, EventArgs e) { var connection = sender as IWebSocketConnection ?? throw new ArgumentException($"{nameof(sender)} is not of type {nameof(IWebSocketConnection)}", nameof(sender)); _logger.LogDebug("Removing websocket from session {Session}", _session.Id); _sockets.Remove(connection); connection.Closed -= OnConnectionClosed; - _sessionManager.CloseIfNeeded(_session); + await _sessionManager.CloseIfNeededAsync(_session).ConfigureAwait(false); } /// diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index c865560958..b16399598c 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -352,6 +352,6 @@ namespace MediaBrowser.Controller.Session /// Task. Task RevokeUserTokens(Guid userId, string currentAccessToken); - void CloseIfNeeded(SessionInfo session); + Task CloseIfNeededAsync(SessionInfo session); } } From d8f1a87c85162a7070a29d9cb95df1e6d115e7bd Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Fri, 27 May 2022 16:25:31 -0600 Subject: [PATCH 3/3] Update Emby.Server.Implementations/Session/SessionManager.cs Co-authored-by: Claus Vium --- Emby.Server.Implementations/Session/SessionManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index eaf2c25daf..d25376297f 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -338,7 +338,7 @@ namespace Emby.Server.Implementations.Session _activeConnections.TryRemove(key, out _); if (!string.IsNullOrEmpty(session.PlayState?.LiveStreamId)) { - await _mediaSourceManager.CloseLiveStream(session.PlayState?.LiveStreamId).ConfigureAwait(false); + await _mediaSourceManager.CloseLiveStream(session.PlayState.LiveStreamId).ConfigureAwait(false); } OnSessionEnded(session);