When connecting to the server socket send the state right away
This commit is contained in:
parent
c943246e33
commit
7b1ebd790d
10
websocket.go
10
websocket.go
|
@ -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},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user