|
@@ -8,6 +8,7 @@ import com.qmth.themis.business.enums.MqEnum;
|
|
|
import com.qmth.themis.business.enums.SystemOperationEnum;
|
|
|
import com.qmth.themis.business.util.JacksonUtil;
|
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
|
+import com.qmth.themis.business.util.WebsocketUtil;
|
|
|
import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
|
import com.qmth.themis.common.signature.SignatureInfo;
|
|
@@ -27,6 +28,7 @@ import javax.websocket.server.PathParam;
|
|
|
import javax.websocket.server.ServerEndpoint;
|
|
|
import java.io.IOException;
|
|
|
import java.lang.reflect.Method;
|
|
|
+import java.net.InetSocketAddress;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.*;
|
|
@@ -49,16 +51,14 @@ public class WebSocketServer
|
|
|
/**
|
|
|
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
|
|
|
*/
|
|
|
- private Session session;
|
|
|
- private String sessionId;
|
|
|
- private Long recordId;
|
|
|
- private String platform = null;
|
|
|
- private String deviceId = null;
|
|
|
- private String Authorization = null;
|
|
|
+ private Session session = null;
|
|
|
+ private String sessionId = null, ip = null;
|
|
|
+ private Long recordId = null;
|
|
|
+ private String platform = null, deviceId = null, Authorization = null;
|
|
|
private Long time = null;
|
|
|
private RedisUtil redisUtil;
|
|
|
private Long updateTime = null;
|
|
|
- private Map<String, Object> tranMap;
|
|
|
+ private Map<String, Object> tranMap = null;
|
|
|
|
|
|
/**
|
|
|
* 连接建立成功调用的方法
|
|
@@ -111,12 +111,13 @@ public class WebSocketServer
|
|
|
//发送恢复网络mq消息
|
|
|
log.info("用户连接:" + this.sessionId + ",当前在线人数为:" + getOnlineCount());
|
|
|
try {
|
|
|
- this.sendMessage("连接成功");
|
|
|
+ InetSocketAddress addr = (InetSocketAddress) WebsocketUtil.getFieldInstance(this.session.getAsyncRemote(), "base#socketWrapper#socket#sc#remoteAddress");
|
|
|
+ this.ip = addr.toString().replace("/", "").split(":")[0];
|
|
|
+ this.sendMessage("ip[" + this.ip + "]连接成功");
|
|
|
tranMap = new HashMap<>();
|
|
|
tranMap.put("recordId", this.recordId);
|
|
|
tranMap.put("deviceId", this.deviceId);
|
|
|
- //todo 这里获取真实ip
|
|
|
- tranMap.put("ip", "");
|
|
|
+ tranMap.put("ip", this.ip);
|
|
|
tranMap.put("updateTime", this.updateTime);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
@@ -136,6 +137,7 @@ public class WebSocketServer
|
|
|
*/
|
|
|
@OnClose
|
|
|
public void onClose() {
|
|
|
+ log.info("onClose is come in");
|
|
|
if (webSocketMap.containsKey(this.sessionId)) {
|
|
|
webSocketMap.remove(this.sessionId);
|
|
|
//从set中删除
|