diff options
Diffstat (limited to 'cmd/dolmetschctld/web_socket.go')
-rw-r--r-- | cmd/dolmetschctld/web_socket.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cmd/dolmetschctld/web_socket.go b/cmd/dolmetschctld/web_socket.go index 9b5d74e..3879650 100644 --- a/cmd/dolmetschctld/web_socket.go +++ b/cmd/dolmetschctld/web_socket.go @@ -52,6 +52,11 @@ type webSocketResponseState struct { webState } +type webSocketResponseLanguages struct { + webSocketResponseBase + Languages []Language `json:"languages"` +} + func sendWebSocketResponse(ws *websocket.Conn, rd interface{}) { if err := ws.WriteJSON(rd); err != nil { log.Println("Web(socket) client", ws.RemoteAddr(), "write error:", err) @@ -79,6 +84,17 @@ func webSocketHandleCommand(ws *websocket.Conn, sm *StateMachine, req webSocketR result.Type = "state" result.State, result.Ratio, result.Lang = sm.GetState() sendWebSocketResponse(ws, result) + case "languages": + if len(req.Args) != 0 { + sendWebSocketErrorResponse(ws, http.StatusBadRequest, "command 'languages' expects no arguments") + return + } + + var result webSocketResponseLanguages + result.ResponseCode = http.StatusOK + result.Type = "languages" + result.Languages = sm.GetLanguages() + sendWebSocketResponse(ws, result) case "language": if len(req.Args) != 1 { sendWebSocketErrorResponse(ws, http.StatusBadRequest, "command 'language' expects exatly one argument") |