|
@@ -1,5 +1,6 @@
|
|
|
package org.thyy.socket.service.IntergrationPlatform;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -54,6 +55,13 @@ public class IntergrationPlatform implements Business {
|
|
|
if (data.equals("heart-beat")) {
|
|
|
Business.send(session, data);
|
|
|
}
|
|
|
+ Business.attemptToConvertJson(data, (value) -> {
|
|
|
+ if (value.getString("code").equals("getOnlineCount")) {
|
|
|
+ Business.send(session, StrUtil.format("""
|
|
|
+ {"code": "onlineCount" , "message": {} }
|
|
|
+ """, sessionContainer.size()));
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -96,11 +104,8 @@ public class IntergrationPlatform implements Business {
|
|
|
|
|
|
private void executeSendMessage(String sid, String msg) {
|
|
|
List<WebSocketSession> sessionList = sessionContainer.get(sid);
|
|
|
- try {
|
|
|
- for (WebSocketSession item : sessionList) {
|
|
|
- item.sendMessage(new TextMessage(msg));
|
|
|
- }
|
|
|
- } catch (Exception ignored) {
|
|
|
+ for (WebSocketSession item : sessionList) {
|
|
|
+ Business.send(item, msg);
|
|
|
}
|
|
|
}
|
|
|
}
|