From cc057177b2fb17aee9a173a6adbabdc578fd74c7 Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Mon, 06 Dec 2021 10:30:44 +0800
Subject: [PATCH] 1.许可

---
 src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java |   28 ++++++++++------------------
 1 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java b/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
index 2e4796d..a2c7987 100644
--- a/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
+++ b/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
@@ -15,7 +15,6 @@
 import io.netty.util.AttributeKey;
 import io.netty.util.CharsetUtil;
 import org.springblade.modules.nettyServer.NettyConfig;
-import org.springblade.modules.suser.service.ISuserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -26,10 +25,7 @@
 
 	private WebSocketServerHandshaker handshaker;
 
-	private  String on=null;
-
-	@Autowired
-	private  ISuserService suserService;
+	private String on = null;
 
 	private static WebSocketHandler webSocketHandler;
 
@@ -63,7 +59,7 @@
 		//用户离线状态
 		String name = ChannelSupervise.findName(ctx.channel().id().asShortText());
 		System.out.println(name);
-		if ( name != null &&!name.equals("ping") ){
+		if (name != null && !name.equals("ping")) {
 			NettyConfig.getChannelGroup().remove(ctx.channel());
 			removeUserId(ctx);
 		}
@@ -95,15 +91,15 @@
 		// 返回应答消息
 		String request = ((TextWebSocketFrame) frame).text();
 
-		if (!request.equals("ping")){
+		if (!request.equals("ping")) {
 
 			JSONObject jsonObj = JSON.parseObject(request);
 			String type = jsonObj.get("type").toString();
 
-			if (type != null && type.equals("login")){
+			if (type != null && type.equals("login")) {
 				//登录链接
 				String id = jsonObj.get("id").toString();
-				NettyConfig.getUserChannelMap().put(id,ctx.channel());
+				NettyConfig.getUserChannelMap().put(id, ctx.channel());
 
 				System.out.println(jsonObj.get("type"));
 				System.out.println(jsonObj.get("id"));
@@ -112,14 +108,8 @@
 				AttributeKey<String> key = AttributeKey.valueOf("userId");
 				ctx.channel().attr(key).setIfAbsent(id);
 				//把用户信息添加到通道里
-				ChannelSupervise.addChannel(ctx.channel(),id);
+				ChannelSupervise.addChannel(ctx.channel(), id);
 			}
-
-
-
-
-
-
 		}
 
 //		TextWebSocketFrame tws = new TextWebSocketFrame(new Date().toString()
@@ -146,7 +136,7 @@
 		}
 		//握手
 		WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
-			"ws://localhost:9034/websocket", null, false);
+			"ws://localhost:2086/websocket", null, false);
 		handshaker = wsFactory.newHandshaker(req);
 		if (handshaker == null) {
 			WebSocketServerHandshakerFactory
@@ -174,6 +164,7 @@
 //			f.addListener(ChannelFutureListener.CLOSE);
 //		}
 	}
+
 	@Override
 	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
 		cause.printStackTrace();
@@ -182,9 +173,10 @@
 
 	/**
 	 * 删除用户与channel 对应关系
+	 *
 	 * @param ctx
 	 */
-	private void removeUserId(ChannelHandlerContext ctx){
+	private void removeUserId(ChannelHandlerContext ctx) {
 		AttributeKey<String> key = AttributeKey.valueOf("userId");
 		String userId = ctx.channel().attr(key).get();
 		NettyConfig.getUserChannelMap().remove(userId);

--
Gitblit v1.9.3