When connecting to the server socket send the state right away

This commit is contained in:
Dane Everitt 2019-05-27 16:58:05 -07:00
parent c943246e33
commit 7b1ebd790d
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 6 additions and 6 deletions

View File

@ -255,4 +255,4 @@ func (s *Server) SetState(state string) error {
// then crashed.
return nil
}
}

View File

@ -16,8 +16,6 @@ const (
SetStateEvent = "set state"
SendServerLogsEvent = "send logs"
SendCommandEvent = "send command"
ConsoleOutputEvent = "console output"
ServerStatusEvent = "status"
)
type WebsocketMessage struct {
@ -61,14 +59,14 @@ func (rt *Router) routeWebsocket(w http.ResponseWriter, r *http.Request, ps http
handleOutput := func(data string) {
handler.SendJson(&WebsocketMessage{
Event: ConsoleOutputEvent,
Event: server.ConsoleOutputEvent,
Args: []string{data},
})
}
handleServerStatus := func(data string) {
handler.SendJson(&WebsocketMessage{
Event: ServerStatusEvent,
Event: server.StatusEvent,
Args: []string{data},
})
}
@ -79,6 +77,8 @@ func (rt *Router) routeWebsocket(w http.ResponseWriter, r *http.Request, ps http
s.AddListener(server.ConsoleOutputEvent, &handleOutput)
defer s.RemoveListener(server.ConsoleOutputEvent, &handleOutput)
s.Emit(server.StatusEvent, s.State)
for {
j := WebsocketMessage{inbound: true}
@ -150,7 +150,7 @@ func (wsh *WebsocketHandler) HandleInbound(m WebsocketMessage) error {
for _, line := range logs {
wsh.SendJson(&WebsocketMessage{
Event: ConsoleOutputEvent,
Event: server.ConsoleOutputEvent,
Args: []string{line},
})
}