updated session events.

This commit is contained in:
Miroslav Šedivý 2020-12-02 18:59:32 +01:00
parent cf47b7e2fa
commit 1f5c0a3547
3 changed files with 26 additions and 0 deletions

View File

@ -63,6 +63,7 @@ func (manager *SessionManagerCtx) Create(id string, profile types.MemberProfile)
} }
manager.members[id] = session manager.members[id] = session
manager.emmiter.Emit("created", session)
return session return session
} }
@ -83,6 +84,7 @@ func (manager *SessionManagerCtx) Delete(id string) error {
return fmt.Errorf("Member not found.") return fmt.Errorf("Member not found.")
} }
manager.emmiter.Emit("deleted", session)
delete(manager.members, id) delete(manager.members, id)
if session.IsConnected() { 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)) { func (manager *SessionManagerCtx) OnConnected(listener func(session types.Session)) {
manager.emmiter.On("connected", func(payload ...interface{}) { manager.emmiter.On("connected", func(payload ...interface{}) {
listener(payload[0].(*SessionCtx)) 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 // config
// --- // ---

View File

@ -61,6 +61,7 @@ func (session *SessionCtx) CanAccessClipboard() bool {
func (session *SessionCtx) SetProfile(profile types.MemberProfile) { func (session *SessionCtx) SetProfile(profile types.MemberProfile) {
session.profile = profile session.profile = profile
session.manager.emmiter.Emit("profile_updated", session)
} }
// --- // ---

View File

@ -58,8 +58,13 @@ type SessionManager interface {
OnHost(listener func(session Session)) OnHost(listener func(session Session))
OnHostCleared(listener func(session Session)) OnHostCleared(listener func(session Session))
OnCreated(listener func(session Session))
OnDeleted(listener func(session Session))
OnConnected(listener func(session Session)) OnConnected(listener func(session Session))
OnDisconnected(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 ImplicitHosting() bool