Skip to content

Commit

Permalink
using rowWebsocketSession in publishers
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehr committed Aug 13, 2020
1 parent 79dce85 commit f5ee805
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/main/java/labs/psychogen/row/event/PublishStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public String name() {

@Override
public void publish(String json, RowWebsocketSession rowWebsocketSession, Subscription subscription) throws IOException {
WebSocketSession session = rowWebsocketSession.getSession();
if(subscription.info().getSessionId().equals(session.getId())){
session.sendMessage(new TextMessage(json));
if(subscription.info().getSessionId().equals(rowWebsocketSession.getSession().getId())){
rowWebsocketSession.getSession().sendMessage(new TextMessage(json));
}
}
}),
Expand All @@ -32,8 +31,7 @@ public String name() {

@Override
public void publish(String json, RowWebsocketSession rowWebsocketSession, Subscription subscription) throws IOException {
WebSocketSession session = rowWebsocketSession.getSession();
session.sendMessage(new TextMessage(json));
rowWebsocketSession.getSession().sendMessage(new TextMessage(json));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import labs.psychogen.row.domain.RowWebsocketSession;
import labs.psychogen.row.domain.protocol.ResponseDto;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
Expand All @@ -15,17 +16,17 @@ public RawMessagePublisherService(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

public void publish(WebSocketSession webSocketSession, Object message) throws IOException {
public void publish(RowWebsocketSession rowWebsocketSession, Object message) throws IOException {
ResponseDto responseDto = new ResponseDto();
responseDto.setBody(message);
webSocketSession.sendMessage(new TextMessage(objectMapper.writeValueAsString(responseDto)));
rowWebsocketSession.getSession().sendMessage(new TextMessage(objectMapper.writeValueAsString(responseDto)));
}

public void publish(WebSocketSession webSocketSession, String message) throws IOException {
public void publish(RowWebsocketSession rowWebsocketSession, String message) throws IOException {
ResponseDto responseDto = new ResponseDto();
JsonNode jsonNode = objectMapper.valueToTree(message);
responseDto.setBody(jsonNode);
webSocketSession.sendMessage(new TextMessage(objectMapper.writeValueAsString(responseDto)));
rowWebsocketSession.getSession().sendMessage(new TextMessage(objectMapper.writeValueAsString(responseDto)));
}

}

0 comments on commit f5ee805

Please sign in to comment.