aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java')
-rw-r--r--juick-server/src/main/java/com/juick/server/WebsocketManager.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/WebsocketManager.java b/juick-server/src/main/java/com/juick/server/WebsocketManager.java
index bcb17bf1..85950c2c 100644
--- a/juick-server/src/main/java/com/juick/server/WebsocketManager.java
+++ b/juick-server/src/main/java/com/juick/server/WebsocketManager.java
@@ -20,11 +20,13 @@ package com.juick.server;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.User;
import com.juick.server.helpers.AnonymousUser;
+import com.juick.server.helpers.CommandResult;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.HttpNotFoundException;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,6 +36,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.PingMessage;
+import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator;
import org.springframework.web.socket.handler.TextWebSocketHandler;
@@ -148,6 +151,18 @@ public class WebsocketManager extends TextWebSocketHandler {
}
});
}
+
+ @Override
+ protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
+ User user = clients.stream().filter(c -> c.session.equals(session)).map(c -> c.visitor)
+ .findFirst().orElse(AnonymousUser.INSTANCE);
+ String command = message.getPayload().trim();
+ if (StringUtils.isNotEmpty(command)) {
+ CommandResult result = commandsManager.processCommand(user, command, URI.create(""));
+ session.sendMessage(new TextMessage(result.getText()));
+ }
+ }
+
public List<SocketSubscribed> getClients() {
return clients;
}