|
@@ -48,6 +48,7 @@ public class WebSocket {
|
|
|
throw new CustomException(ResultEnum.UNAUTHORIZED.getRespCode(), ResultEnum.UNAUTHORIZED.getRespMsg());
|
|
|
}
|
|
|
this.userId = Convert.toStr(redisUtil.get(token));
|
|
|
+ redisUtil.set("websocket" + userId, true);
|
|
|
this.token = token;
|
|
|
this.session = session;
|
|
|
webSocketSet.add(this);
|
|
@@ -57,9 +58,13 @@ public class WebSocket {
|
|
|
//前端关闭一个webSocket时
|
|
|
@OnClose
|
|
|
public void onClose() {
|
|
|
- //清空相应的token
|
|
|
- if (Blank.isNotEmpty(token)) {
|
|
|
- redisUtil.del(token);
|
|
|
+ try {
|
|
|
+ Thread.sleep(10000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ if ((Boolean) redisUtil.get("websocket" + userId)) {
|
|
|
+ return;
|
|
|
}
|
|
|
if (Blank.isNotEmpty(userId)) {
|
|
|
String userLoginType = token.substring(0, 5);
|
|
@@ -73,6 +78,10 @@ public class WebSocket {
|
|
|
throw new CustomException(ResultEnum.UNAUTHORIZED.getRespCode(), ResultEnum.UNAUTHORIZED.getRespMsg());
|
|
|
}
|
|
|
}
|
|
|
+ //清空相应的token
|
|
|
+ if (Blank.isNotEmpty(token)) {
|
|
|
+ redisUtil.del(token);
|
|
|
+ }
|
|
|
webSocketSet.remove(this);
|
|
|
}
|
|
|
|