洪城义警-正式版后台
zengh
2022-05-26 4c19ddd36bdfb43b5ef4e8df3c9a98cd4d356d6c
src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
@@ -62,6 +62,7 @@
      System.out.println("客户端断开连接:" + ctx.channel());
      //用户离线状态
      String name = ChannelSupervise.findName(ctx.channel().id().asShortText());
      System.out.println(name);
      if ( name != null &&!name.equals("ping") ){
         NettyConfig.getChannelGroup().remove(ctx.channel());
         removeUserId(ctx);
@@ -103,9 +104,10 @@
            //登录链接
            String id = jsonObj.get("id").toString();
            NettyConfig.getUserChannelMap().put(id,ctx.channel());
            NettyConfig.getChannelGroup().add(ctx.channel());
            System.out.println(jsonObj.get("type"));
            System.out.println(jsonObj.get("id"));
            System.out.println("___________________"+jsonObj.get("type"));
            System.out.println(jsonObj.get("id")+ "____________________________用户连接成功");
            //将用户id作为自定义属性加入到channel 中,方便随时channel中获取用户id
            AttributeKey<String> key = AttributeKey.valueOf("userId");
@@ -113,11 +115,6 @@
            //把用户信息添加到通道里
            ChannelSupervise.addChannel(ctx.channel(),id);
         }
      }