From 7d66a578a2b18112825a0f8aa81d40ce5a37d76d Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Thu, 12 Aug 2021 16:41:11 +0800
Subject: [PATCH] 视频通话
---
src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java | 24 +++++++++---------------
1 files changed, 9 insertions(+), 15 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..535134a 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,12 +108,8 @@
AttributeKey<String> key = AttributeKey.valueOf("userId");
ctx.channel().attr(key).setIfAbsent(id);
//把用户信息添加到通道里
- ChannelSupervise.addChannel(ctx.channel(),id);
+ ChannelSupervise.addChannel(ctx.channel(), id);
}
-
-
-
-
}
@@ -174,6 +166,7 @@
// f.addListener(ChannelFutureListener.CLOSE);
// }
}
+
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
@@ -182,9 +175,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