|
|
@@ -6,6 +6,8 @@ import cn.reghao.tnb.account.api.dto.AuthedAccount;
|
|
|
import cn.reghao.tnb.account.api.iface.AccountQuery;
|
|
|
import cn.reghao.tnb.message.api.model.EventType;
|
|
|
import cn.reghao.tnb.message.api.model.resp.EventMessageResp;
|
|
|
+import cn.reghao.tnb.message.app.rabbit.RabbitProducer;
|
|
|
+import cn.reghao.tnb.message.app.ws.msg.EventMessage;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
import com.google.gson.JsonObject;
|
|
|
@@ -32,6 +34,11 @@ public class WsConnectionChat {
|
|
|
private final Map<String, Long> sessionMap = new HashMap<>();
|
|
|
private final Map<Long, WebSocketSession> userMap = new HashMap<>();
|
|
|
private final Gson gson = new GsonBuilder().create();
|
|
|
+ private final RabbitProducer rabbitProducer;
|
|
|
+
|
|
|
+ public WsConnectionChat(RabbitProducer rabbitProducer) {
|
|
|
+ this.rabbitProducer = rabbitProducer;
|
|
|
+ }
|
|
|
|
|
|
public void online(WebSocketSession session) throws IOException {
|
|
|
String query = session.getUri().getQuery();
|
|
|
@@ -93,13 +100,13 @@ public class WsConnectionChat {
|
|
|
data.get("receiverId").getAsLong();
|
|
|
break;
|
|
|
case event_talk:
|
|
|
+ rabbitProducer.sendChatMessage(payload);
|
|
|
JsonObject data1 = jsonObject.get("data").getAsJsonObject();
|
|
|
long senderId = data1.get("senderId").getAsLong();
|
|
|
long receiverId = data1.get("receiverId").getAsLong();
|
|
|
String content = data1.get("content").getAsString();
|
|
|
- log.info("send {} -> {}", receiverId, content);
|
|
|
-
|
|
|
- WebSocketSession webSocketSession = userMap.get(receiverId);
|
|
|
+ //log.info("send {} -> {}", receiverId, content);
|
|
|
+ /*WebSocketSession webSocketSession = userMap.get(receiverId);
|
|
|
if (webSocketSession != null) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("senderId", senderId);
|
|
|
@@ -108,7 +115,7 @@ public class WsConnectionChat {
|
|
|
sendMessage(webSocketSession, map);
|
|
|
} else {
|
|
|
log.error("not found {} session", receiverId);
|
|
|
- }
|
|
|
+ }*/
|
|
|
break;
|
|
|
case event_talk_revoke:
|
|
|
log.info("talk_revoke event");
|
|
|
@@ -128,15 +135,17 @@ public class WsConnectionChat {
|
|
|
session.sendMessage(textMessage);
|
|
|
}
|
|
|
|
|
|
- public void sendTextMessage(long userId, String text) {
|
|
|
+ public void sendTextMessage(long userId, Object payload) {
|
|
|
WebSocketSession session = userMap.get(userId);
|
|
|
if (session != null) {
|
|
|
- TextMessage textMessage = new TextMessage(text);
|
|
|
+ TextMessage textMessage = new TextMessage(gson.toJson(payload));
|
|
|
try {
|
|
|
session.sendMessage(textMessage);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ } else {
|
|
|
+ log.info("receiver {} not found", userId);
|
|
|
}
|
|
|
}
|
|
|
}
|