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

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