fix(remote): live auth-context refresh + lifecycle races

Keep a running companion-remote host's crypto identity in sync with the
active profile: subscribe to PlexHome/connection/join streams and rebuild
auth contexts (restarting the broadcast when they change) so a removed
home user or revoked borrowed connection stops controlling the host.

Serialize host start/stop/crypto-rebuild through a lifecycle lock, clean
up peer subscriptions before re-listening, and guard the replaced-client
onDone against clobbering the new client's session. Drop the context.mounted
guards that aborted an app-level host start, fix the DiscoveryView
init-flash/stuck-on-throw, and delete the dead initialize*Crypto helpers.
This commit is contained in:
edde746
2026-07-02 11:41:25 +02:00
parent 2b7142bdcd
commit d193633a5d
6 changed files with 271 additions and 131 deletions
@@ -388,7 +388,10 @@ class CompanionRemotePeerService with KeepaliveMixin {
onDone: () {
authTimeout?.cancel();
appLogger.d('CompanionRemote: WebSocket connection closed');
if (isAuthenticated) {
// A replaced client's socket closes AFTER the new client already took
// over `_clientSocket`; only the socket that still owns the session may
// tear it down, or we'd clobber the live connection.
if (isAuthenticated && identical(_clientSocket, socket)) {
_clientSocket = null;
_sessionEncKey = null;
_isAuthenticated = false;