aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'juick-ws/src/main/java/com')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java51
1 files changed, 1 insertions, 50 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
index bdf6dba6..599d1394 100644
--- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
+++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
@@ -51,7 +51,7 @@ import java.util.List;
/**
* Created by vitalyster on 28.06.2016.
*/
-public class WebsocketComponent extends TextWebSocketHandler implements ProtocolListener {
+public class WebsocketComponent extends TextWebSocketHandler {
private static final Logger logger = LoggerFactory.getLogger(WebsocketComponent.class);
private final List<SocketSubscribed> clients = Collections.synchronizedList(new LinkedList<>());
@@ -62,13 +62,7 @@ public class WebsocketComponent extends TextWebSocketHandler implements Protocol
private MessagesService messagesService;
@Inject
private SubscriptionService subscriptionService;
- @Inject
- private JuickProtocol protocol;
- @PostConstruct
- public void init() {
- protocol.setListener(this);
- }
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
@@ -148,53 +142,10 @@ public class WebsocketComponent extends TextWebSocketHandler implements Protocol
}
});
}
-
- @Override
- protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
- getClients().stream().filter(s -> !s.legacy && s.session.equals(session)).forEach(s -> {
- User user = s.visitor;
- String input = message.getPayload();
- if (StringUtils.isNotBlank(input)) {
- try {
- s.session.sendMessage(new TextMessage(protocol.getReply(user, input)));
- } catch (IOException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
- logger.error("protocol exception", e);
- }
- }
- });
- }
-
public List<SocketSubscribed> getClients() {
return clients;
}
- @Override
- public void privateMessage(User from, User to, String body) {
- notifyUser(from, to, "Private message from @" + from.getName() + ":\n" + body);
- }
-
- @Override
- public void userSubscribed(User from, User to) {
- notifyUser(from, to, String.format("@%s subscribed to your blog", from.getName()));
- }
-
- @Override
- public void messagePosted(Message msg) {
- subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid()).forEach(u -> {
- notifyUser(msg.getUser(), u, msg.getText());
- });
- }
-
- private void notifyUser(User from, User to, String body) {
- getClients().stream().filter(s -> !s.legacy && s.visitor.equals(to)).forEach(s -> {
- try {
- s.session.sendMessage(new TextMessage(body));
- } catch (IOException e) {
- logger.error("protocol exception", e);
- }
- });
- }
-
class SocketSubscribed {
WebSocketSession session;
String clientName;