diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-11-08 10:53:39 +0100 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-11-08 10:53:39 +0100 |
commit | 0a5ab2ca1ab89e6e667b7f9c7bdffdff036ca9b7 (patch) | |
tree | bdc803f2d02347540d221bb9fc9f8c4b6e748481 /lib/agent/events.go | |
parent | 02aec942b44eecd2ea9b311bb4ba2d60cce21e9a (diff) |
Unregistered events when client WS session is closed.
Diffstat (limited to 'lib/agent/events.go')
-rw-r--r-- | lib/agent/events.go | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/lib/agent/events.go b/lib/agent/events.go index 2684ff5..9ff72ac 100644 --- a/lib/agent/events.go +++ b/lib/agent/events.go @@ -7,13 +7,6 @@ import ( "github.com/iotbzh/xds-agent/lib/apiv1" ) -var _EVTAllList = []string{ - apiv1.EVTServerConfig, - apiv1.EVTProjectAdd, - apiv1.EVTProjectDelete, - apiv1.EVTProjectChange, -} - // EventDef Definition on one event type EventDef struct { sids map[string]int @@ -28,7 +21,7 @@ type Events struct { // NewEvents creates an instance of Events func NewEvents(ctx *Context) *Events { evMap := make(map[string]*EventDef) - for _, ev := range _EVTAllList { + for _, ev := range apiv1.EVTAllList { evMap[ev] = &EventDef{ sids: make(map[string]int), } @@ -41,12 +34,12 @@ func NewEvents(ctx *Context) *Events { // GetList returns the list of all supported events func (e *Events) GetList() []string { - return _EVTAllList + return apiv1.EVTAllList } // Register Used by a client/session to register to a specific (or all) event(s) func (e *Events) Register(evName, sessionID string) error { - evs := _EVTAllList + evs := apiv1.EVTAllList if evName != apiv1.EVTAll { if _, ok := e.eventsMap[evName]; !ok { return fmt.Errorf("Unsupported event type name") @@ -61,7 +54,7 @@ func (e *Events) Register(evName, sessionID string) error { // UnRegister Used by a client/session to unregister event(s) func (e *Events) UnRegister(evName, sessionID string) error { - evs := _EVTAllList + evs := apiv1.EVTAllList if evName != apiv1.EVTAll { if _, ok := e.eventsMap[evName]; !ok { return fmt.Errorf("Unsupported event type name") @@ -95,7 +88,7 @@ func (e *Events) Emit(evName string, data interface{}) error { so := e.webServer.sessions.IOSocketGet(sid) if so == nil { if firstErr == nil { - firstErr = fmt.Errorf("IOSocketGet return nil") + firstErr = fmt.Errorf("IOSocketGet return nil (SID=%v)", sid) } continue } |