diff --git a/internal/session/manager.go b/internal/session/manager.go index d215ce9c..094f1699 100644 --- a/internal/session/manager.go +++ b/internal/session/manager.go @@ -63,6 +63,7 @@ func (manager *SessionManagerCtx) Create(id string, profile types.MemberProfile) } manager.members[id] = session + manager.emmiter.Emit("created", session) return session } @@ -83,6 +84,7 @@ func (manager *SessionManagerCtx) Delete(id string) error { return fmt.Errorf("Member not found.") } + manager.emmiter.Emit("deleted", session) delete(manager.members, id) if session.IsConnected() { @@ -214,6 +216,18 @@ func (manager *SessionManagerCtx) OnHostCleared(listener func(session types.Sess }) } +func (manager *SessionManagerCtx) OnCreated(listener func(session types.Session)) { + manager.emmiter.On("created", func(payload ...interface{}) { + listener(payload[0].(*SessionCtx)) + }) +} + +func (manager *SessionManagerCtx) OnDeleted(listener func(session types.Session)) { + manager.emmiter.On("deleted", func(payload ...interface{}) { + listener(payload[0].(*SessionCtx)) + }) +} + func (manager *SessionManagerCtx) OnConnected(listener func(session types.Session)) { manager.emmiter.On("connected", func(payload ...interface{}) { listener(payload[0].(*SessionCtx)) @@ -238,6 +252,12 @@ func (manager *SessionManagerCtx) OnReceivingStopped(listener func(session types }) } +func (manager *SessionManagerCtx) OnProfileUpdated(listener func(session types.Session)) { + manager.emmiter.On("profile_updated", func(payload ...interface{}) { + listener(payload[0].(*SessionCtx)) + }) +} + // --- // config // --- diff --git a/internal/session/session.go b/internal/session/session.go index 0e280aa2..eb97f994 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -61,6 +61,7 @@ func (session *SessionCtx) CanAccessClipboard() bool { func (session *SessionCtx) SetProfile(profile types.MemberProfile) { session.profile = profile + session.manager.emmiter.Emit("profile_updated", session) } // --- diff --git a/internal/types/session.go b/internal/types/session.go index c3e3ed06..70106950 100644 --- a/internal/types/session.go +++ b/internal/types/session.go @@ -58,8 +58,13 @@ type SessionManager interface { OnHost(listener func(session Session)) OnHostCleared(listener func(session Session)) + OnCreated(listener func(session Session)) + OnDeleted(listener func(session Session)) OnConnected(listener func(session Session)) OnDisconnected(listener func(session Session)) + OnReceivingStarted(listener func(session Session)) + OnReceivingStopped(listener func(session Session)) + OnProfileUpdated(listener func(session Session)) ImplicitHosting() bool