From 2467c94c59e66b5cf868c9d614cbfd84aa2d59e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 6 Dec 2020 19:29:39 +0100 Subject: [PATCH] add profileChanged. --- internal/session/manager.go | 1 + internal/session/session.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/internal/session/manager.go b/internal/session/manager.go index e11e00fb..d3fb9e32 100644 --- a/internal/session/manager.go +++ b/internal/session/manager.go @@ -142,6 +142,7 @@ func (manager *SessionManagerCtx) Update(id string, profile types.MemberProfile) manager.membersMu.Unlock() manager.emmiter.Emit("profile_changed", session) + session.profileChanged() return nil } diff --git a/internal/session/session.go b/internal/session/session.go index 4d74c691..c2ccdd57 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -59,6 +59,24 @@ func (session *SessionCtx) CanAccessClipboard() bool { return session.profile.CanAccessClipboard } +func (session *SessionCtx) profileChanged() { + if !session.CanHost() && session.IsHost() { + session.manager.ClearHost() + } + + if !session.CanWatch() && session.IsWatching() { + if err := session.webrtc_peer.Destroy(); err != nil { + session.logger.Warn().Err(err).Msgf("webrtc destroy has failed") + } + } + + if !session.CanConnect() && session.IsConnected() { + if err := session.Disconnect("profile changed"); err != nil { + session.logger.Warn().Err(err).Msgf("websocket destroy has failed") + } + } +} + // --- // runtime // ---