aboutsummaryrefslogtreecommitdiffstats
path: root/lib/agent
diff options
context:
space:
mode:
Diffstat (limited to 'lib/agent')
-rw-r--r--lib/agent/events.go17
-rw-r--r--lib/agent/project-st.go4
-rw-r--r--lib/agent/webserver.go2
3 files changed, 9 insertions, 14 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
}
diff --git a/lib/agent/project-st.go b/lib/agent/project-st.go
index cd55656..e2cd3cb 100644
--- a/lib/agent/project-st.go
+++ b/lib/agent/project-st.go
@@ -143,7 +143,7 @@ func (p *STProject) _cbServerFolderChanged(pData interface{}, data interface{})
p.folder.DataCloudSync.STSvrStatus = evt.Folder.Status
if err := p.events.Emit(apiv1.EVTProjectChange, p.server.FolderToProject(*p.folder)); err != nil {
- p.Log.Warningf("Cannot notify project change: %v", err)
+ p.Log.Warningf("Cannot notify project change (from server): %v", err)
}
}
return nil
@@ -182,7 +182,7 @@ func (p *STProject) _cbLocalSTEvents(ev st.Event, data *st.EventsCBData) {
p.folder.DataCloudSync.STLocStatus = sts
if err := p.events.Emit(apiv1.EVTProjectChange, p.server.FolderToProject(*p.folder)); err != nil {
- p.Log.Warningf("Cannot notify project change: %v", err)
+ p.Log.Warningf("Cannot notify project change (local): %v", err)
}
}
}
diff --git a/lib/agent/webserver.go b/lib/agent/webserver.go
index d15236d..b75abd4 100644
--- a/lib/agent/webserver.go
+++ b/lib/agent/webserver.go
@@ -11,6 +11,7 @@ import (
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"github.com/googollee/go-socket.io"
+ "github.com/iotbzh/xds-agent/lib/apiv1"
)
// WebServer .
@@ -233,6 +234,7 @@ func (s *WebServer) socketHandler(c *gin.Context) {
so.On("disconnection", func() {
s.Log.Debugf("WS disconnected (WSID=%s, SID=%s)", so.Id(), sess.ID)
s.sessions.UpdateIOSocket(sess.ID, nil)
+ s.events.UnRegister(apiv1.EVTAll, sess.ID)
})
})