add profileChanged.

This commit is contained in:
Miroslav Šedivý 2020-12-06 19:29:39 +01:00
parent a2da60d617
commit 2467c94c59
2 changed files with 19 additions and 0 deletions

View File

@ -142,6 +142,7 @@ func (manager *SessionManagerCtx) Update(id string, profile types.MemberProfile)
manager.membersMu.Unlock() manager.membersMu.Unlock()
manager.emmiter.Emit("profile_changed", session) manager.emmiter.Emit("profile_changed", session)
session.profileChanged()
return nil return nil
} }

View File

@ -59,6 +59,24 @@ func (session *SessionCtx) CanAccessClipboard() bool {
return session.profile.CanAccessClipboard 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 // runtime
// --- // ---