Browse Source

fix : Websocket调试修改11

bilingfeng 1 năm trước cách đây
mục cha
commit
c1a2d11686

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 <Websocket调试修改3> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <Websocket调试修改11> ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 9 - 3
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/websocket/KfMsgWebsocketHandler.java

@@ -150,10 +150,15 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
      */
     @Override
     public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
-        //从session中获取客服id
-        Long kfUserId = Long.valueOf(session.getAttributes().get("kfUserId").toString());
         //关闭连接
         session.close();
+        //判断会话是否保存
+        Object kfUserIdObject = session.getAttributes().get("kfUserId");
+        if (kfUserIdObject == null) {
+            return;
+        }
+        //从session中获取客服id
+        Long kfUserId = Long.valueOf(kfUserIdObject.toString());
         //移除连接
         kfMsgWebSocketSessionRegistry.removeSession(kfUserId);
     }
@@ -361,7 +366,8 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
             return Boolean.FALSE;
         }
         //添加会话
-        if (kfMsgWebSocketSessionRegistry.getSession(SecurityUtil.getUserId()) == null) {
+        WebSocketSession webSocketSession = kfMsgWebSocketSessionRegistry.getSession(SecurityUtil.getUserId());
+        if (webSocketSession == null) {
             session.getAttributes().put("kfUserId", SecurityUtil.getUserId());
             kfMsgWebSocketSessionRegistry.addSession(SecurityUtil.getUserId(), session);
         }