Skip to content

Commit

Permalink
Merge pull request #74 from e154/develop
Browse files Browse the repository at this point in the history
issues #64 update gate settings
  • Loading branch information
e154 authored Aug 26, 2019
2 parents aaef72e + 6faa963 commit 2c5a99b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
13 changes: 9 additions & 4 deletions api/websocket/controllers/dashboard_models/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()

Expand All @@ -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
}
9 changes: 8 additions & 1 deletion system/gate_client/gate_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -114,6 +120,8 @@ func (g *GateClient) RegisterServer() {

g.settings.GateServerToken = msg.Payload["token"].(string)

g.Restart()

_ = g.SaveSettings()
})
}
Expand Down Expand Up @@ -192,7 +200,6 @@ func (g *GateClient) onMessage(b []byte) {

func (g *GateClient) onConnected() {
g.RegisterServer()
g.BroadcastAccessToken()
}

func (g *GateClient) onClosed() {
Expand Down
3 changes: 3 additions & 0 deletions system/gate_client/ws_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
2 changes: 1 addition & 1 deletion system/stream/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 2c5a99b

Please sign in to comment.