diff --git a/api/websocket/controllers/dashboard_models/gate.go b/api/websocket/controllers/dashboard_models/gate.go index ff411cefd..e486408fb 100644 --- a/api/websocket/controllers/dashboard_models/gate.go +++ b/api/websocket/controllers/dashboard_models/gate.go @@ -8,7 +8,7 @@ import ( type Gate struct { gate *gate_client.GateClient Status string `json:"status"` - AccessToken string `json:"access_token"` + AccessToken string `json:"-"` } func NewGate(gate *gate_client.GateClient) *Gate { @@ -31,7 +31,13 @@ func (g *Gate) Update() { // func (g *Gate) GatesStatus(client *stream.Client, message stream.Message) { - payload, _ := g.Broadcast() + g.Update() + + payload := map[string]interface{}{ + "gate_status": g.Status, + "access_token": g.AccessToken, + } + response := message.Response(payload) client.Send <- response.Pack() @@ -43,7 +49,6 @@ func (g *Gate) Broadcast() (map[string]interface{}, bool) { g.Update() return map[string]interface{}{ - "gate_status": g.Status, - "access_token": g.AccessToken, + "gate_status": g.Status, }, true } diff --git a/system/gate_client/gate_client.go b/system/gate_client/gate_client.go index 88128fb08..77fad5981 100644 --- a/system/gate_client/gate_client.go +++ b/system/gate_client/gate_client.go @@ -79,6 +79,12 @@ func (g *GateClient) Connect() { g.wsClient.Connect(g.settings) } +func (g *GateClient) Restart() { + g.Close() + g.Connect() + g.BroadcastAccessToken() +} + func (g *GateClient) BroadcastAccessToken() { log.Info("Broadcast access token") @@ -114,6 +120,8 @@ func (g *GateClient) RegisterServer() { g.settings.GateServerToken = msg.Payload["token"].(string) + g.Restart() + _ = g.SaveSettings() }) } @@ -192,7 +200,6 @@ func (g *GateClient) onMessage(b []byte) { func (g *GateClient) onConnected() { g.RegisterServer() - g.BroadcastAccessToken() } func (g *GateClient) onClosed() { diff --git a/system/gate_client/ws_client.go b/system/gate_client/ws_client.go index cddd2388a..f53ade404 100644 --- a/system/gate_client/ws_client.go +++ b/system/gate_client/ws_client.go @@ -116,6 +116,9 @@ func (client *WsClient) connect() { if strings.Contains(err.Error(), "bad handshake") { return } + if strings.Contains(err.Error(), "use of closed network connection") { + return + } log.Debug(err.Error()) } diff --git a/system/stream/types.go b/system/stream/types.go index 8373c1d4a..212a28621 100644 --- a/system/stream/types.go +++ b/system/stream/types.go @@ -21,7 +21,7 @@ const ( ) type Message struct { - Id uuid.UUID `json:"id"` + Id uuid.UUID `json:"id,omitempty"` Command string `json:"command"` Payload map[string]interface{} `json:"payload"` Forward string `json:"forward"`