From e70a6d41f48b964a82f325244b57aaf86a51af85 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Fri, 11 Dec 2020 09:57:14 +0100 Subject: [PATCH] Merge pull request #4710 from OancaAndrei/syncplay-fix-session-restore Restore sessions in SyncPlay groups upon reconnection (cherry picked from commit a57e465de9c34c15fb6981b752bb5ad4121a2ab5) Signed-off-by: Joshua M. Boniface --- .../Session/SessionManager.cs | 16 ++++++++++++++++ .../Session/SessionWebSocketListener.cs | 2 ++ .../SyncPlay/SyncPlayManager.cs | 6 +++--- .../Session/ISessionManager.cs | 11 +++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index b3965fccad..885f65c64e 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -128,6 +128,9 @@ namespace Emby.Server.Implementations.Session /// public event EventHandler SessionActivity; + /// + public event EventHandler SessionControllerConnected; + /// /// Gets all connections. /// @@ -312,6 +315,19 @@ namespace Emby.Server.Implementations.Session return session; } + /// + public void OnSessionControllerConnected(SessionInfo info) + { + EventHelper.QueueEventIfNotNull( + SessionControllerConnected, + this, + new SessionEventArgs + { + SessionInfo = info + }, + _logger); + } + /// public void CloseIfNeeded(SessionInfo session) { diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs index 169eaefd8b..39c369a01d 100644 --- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs +++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs @@ -133,6 +133,8 @@ namespace Emby.Server.Implementations.Session var controller = (WebSocketController)controllerInfo.Item1; controller.AddWebSocket(connection); + + _sessionManager.OnSessionControllerConnected(session); } /// diff --git a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs index 348213ee15..1d87036a27 100644 --- a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs +++ b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs @@ -81,7 +81,7 @@ namespace Emby.Server.Implementations.SyncPlay _sessionManager = sessionManager; _libraryManager = libraryManager; _logger = loggerFactory.CreateLogger(); - _sessionManager.SessionStarted += OnSessionManagerSessionStarted; + _sessionManager.SessionControllerConnected += OnSessionControllerConnected; } /// @@ -329,11 +329,11 @@ namespace Emby.Server.Implementations.SyncPlay return; } - _sessionManager.SessionStarted -= OnSessionManagerSessionStarted; + _sessionManager.SessionControllerConnected -= OnSessionControllerConnected; _disposed = true; } - private void OnSessionManagerSessionStarted(object sender, SessionEventArgs e) + private void OnSessionControllerConnected(object sender, SessionEventArgs e) { var session = e.SessionInfo; diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index 9ad8557ce6..6c06dcad58 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -46,6 +46,11 @@ namespace MediaBrowser.Controller.Session event EventHandler SessionActivity; + /// + /// Occurs when [session controller connected]. + /// + event EventHandler SessionControllerConnected; + /// /// Occurs when [capabilities changed]. /// @@ -78,6 +83,12 @@ namespace MediaBrowser.Controller.Session /// The user. SessionInfo LogSessionActivity(string appName, string appVersion, string deviceId, string deviceName, string remoteEndPoint, Jellyfin.Data.Entities.User user); + /// + /// Used to report that a session controller has connected. + /// + /// The session. + void OnSessionControllerConnected(SessionInfo session); + void UpdateDeviceName(string sessionId, string reportedDeviceName); ///