diff options
-rw-r--r-- | src/rhimportd/ctrlWebSocket.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/rhimportd/ctrlWebSocket.go b/src/rhimportd/ctrlWebSocket.go index f3e4438..5af59d5 100644 --- a/src/rhimportd/ctrlWebSocket.go +++ b/src/rhimportd/ctrlWebSocket.go @@ -308,6 +308,7 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, binchan <-chan }() listUpdates := make(chan webSocketSessionListUpdate, 5) listUpdateCBArg := webSocketSessionListUpdateCBArg{closed, listUpdates} + alreadyListening := false session := newWebSocketSession() for { @@ -346,11 +347,16 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, binchan <-chan } } case "list": - sessions, code, errstring := sessions.List(reqdata.UserName, reqdata.Password, false, listUpdateCBArg, webSocketListUpdate) - if code != http.StatusOK { - sendWebSocketErrorResponse(ws, code, errstring) + if alreadyListening { + sendWebSocketErrorResponse(ws, http.StatusBadRequest, "This connection already listens for session-list updates") } else { - sendWebSocketListResponse(ws, sessions, nil) + sessions, code, errstring := sessions.List(reqdata.UserName, reqdata.Password, false, listUpdateCBArg, webSocketListUpdate) + if code != http.StatusOK { + sendWebSocketErrorResponse(ws, code, errstring) + } else { + alreadyListening = true + sendWebSocketListResponse(ws, sessions, nil) + } } default: sendWebSocketErrorResponse(ws, http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command)) |