Send the server logs when the websocket is connected to initially

This commit is contained in:
Dane Everitt 2019-05-27 18:03:37 -07:00
parent 93c71a6ab7
commit 2db705f697
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 7 additions and 1 deletions

View File

@ -5,6 +5,7 @@ type EventListeners map[string][]EventListenerFunction
type EventListenerFunction *func(string) type EventListenerFunction *func(string)
// Defines all of the possible output events for a server. // Defines all of the possible output events for a server.
// noinspection GoNameStartsWithPackageName
const ( const (
ConsoleOutputEvent = "console output" ConsoleOutputEvent = "console output"
StatusEvent = "status" StatusEvent = "status"

View File

@ -78,6 +78,9 @@ func (rt *Router) routeWebsocket(w http.ResponseWriter, r *http.Request, ps http
defer s.RemoveListener(server.ConsoleOutputEvent, &handleOutput) defer s.RemoveListener(server.ConsoleOutputEvent, &handleOutput)
s.Emit(server.StatusEvent, s.State) s.Emit(server.StatusEvent, s.State)
if s.State != server.ProcessOfflineState {
handler.HandleInbound(WebsocketMessage{inbound: true, Event: SendServerLogsEvent})
}
for { for {
j := WebsocketMessage{inbound: true} j := WebsocketMessage{inbound: true}
@ -99,6 +102,8 @@ func (rt *Router) routeWebsocket(w http.ResponseWriter, r *http.Request, ps http
if err := handler.HandleInbound(j); err != nil { if err := handler.HandleInbound(j); err != nil {
zap.S().Warnw("error handling inbound websocket request", zap.Error(err)) zap.S().Warnw("error handling inbound websocket request", zap.Error(err))
break break
} else {
zap.S().Debugw("handled event", zap.String("event", j.Event), zap.Strings("args", j.Args))
} }
} }
} }
@ -143,7 +148,7 @@ func (wsh *WebsocketHandler) HandleInbound(m WebsocketMessage) error {
} }
case SendServerLogsEvent: case SendServerLogsEvent:
{ {
logs, err := wsh.Server.Environment.Readlog(1024 * 5) logs, err := wsh.Server.Environment.Readlog(1024 * 16)
if err != nil { if err != nil {
return err return err
} }