From b39cc2beacc1ec2e37cff349cae42e420105c8a6 Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Fri, 05 Nov 2021 14:29:47 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java |   43 ++++++++++++++++++++++++-------------------
 1 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java b/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
index 7ef33f5..2e4796d 100644
--- a/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
+++ b/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
@@ -1,5 +1,7 @@
 package org.springblade.modules.webscoket;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelFuture;
@@ -60,13 +62,8 @@
 		System.out.println("客户端断开连接:" + ctx.channel());
 		//用户离线状态
 		String name = ChannelSupervise.findName(ctx.channel().id().asShortText());
+		System.out.println(name);
 		if ( name != null &&!name.equals("ping") ){
-			String num="0";
-			//工作状态(0闲置,1工作中)
-			String workSt = "0";
-			webSocketHandler.suserService.updateUser(num,name,workSt);
-			//ChannelSupervise.removeChannel(ctx.channel());
-
 			NettyConfig.getChannelGroup().remove(ctx.channel());
 			removeUserId(ctx);
 		}
@@ -100,21 +97,29 @@
 
 		if (!request.equals("ping")){
 
-			NettyConfig.getUserChannelMap().put(request,ctx.channel());
+			JSONObject jsonObj = JSON.parseObject(request);
+			String type = jsonObj.get("type").toString();
 
-			//将用户id作为自定义属性加入到channel 中,方便随时channel中获取用户id
-			AttributeKey<String> key = AttributeKey.valueOf("userId");
-			ctx.channel().attr(key).setIfAbsent(request);
+			if (type != null && type.equals("login")){
+				//登录链接
+				String id = jsonObj.get("id").toString();
+				NettyConfig.getUserChannelMap().put(id,ctx.channel());
 
-			//把用户信息添加到通道里
-			ChannelSupervise.addChannel(ctx.channel(),request);
-			//用户在线状态
-			this.on=request;
-			//在线状态(0掉线,1在线)
-			String num="1";
-			//工作状态(0闲置,1工作中)
-			String workSt = "0";
-			webSocketHandler.suserService.updateUser(num,request,workSt);
+				System.out.println(jsonObj.get("type"));
+				System.out.println(jsonObj.get("id"));
+
+				//将用户id作为自定义属性加入到channel 中,方便随时channel中获取用户id
+				AttributeKey<String> key = AttributeKey.valueOf("userId");
+				ctx.channel().attr(key).setIfAbsent(id);
+				//把用户信息添加到通道里
+				ChannelSupervise.addChannel(ctx.channel(),id);
+			}
+
+
+
+
+
+
 		}
 
 //		TextWebSocketFrame tws = new TextWebSocketFrame(new Date().toString()

--
Gitblit v1.9.3