chenbiao 2 éve
szülő
commit
4391bee6e0
1 módosított fájl, 12 hozzáadás és 11 törlés
  1. 12 11
      midjourney/src/main/java/com/yhlxj/web/wss/WssSession.java

+ 12 - 11
midjourney/src/main/java/com/yhlxj/web/wss/WssSession.java

@@ -33,17 +33,18 @@ public class WssSession implements WssSendable , Serializable {
      */
     @Override
     public void sendMessage(WsMessageTypeEnum type, Object object) {
-
-        //组织成形如 message:{"type":"type", "data":{...}}想
-        JSONObject result = new JSONObject();
-        result.putOpt("type", type.type);
-        result.putOpt("content", JSONUtil.toJsonStr(object));
-
-        logger.info("[WS-SENDMESSAGE],{}", WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
-        try {
-            getSession().getBasicRemote().sendText(WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
-        } catch (Exception e) {
-            logger.info("[WS-SENDMESSAGE],[失败],{}", WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
+        if (session.isOpen()) {
+            //组织成形如 message:{"type":"type", "data":{...}}想
+            JSONObject result = new JSONObject();
+            result.putOpt("type", type.type);
+            result.putOpt("content", JSONUtil.toJsonStr(object));
+
+            logger.info("[WS-SENDMESSAGE],{}", WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
+            try {
+                getSession().getBasicRemote().sendText(WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
+            } catch (Exception e) {
+                logger.info("[WS-SENDMESSAGE],[失败],{}", WsMessageTypeEnum.MESSAGE.type + ":" + result.toString());
+            }
         }
     }