|
@@ -27,7 +27,10 @@ import javax.websocket.server.ServerEndpoint;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
-import java.util.*;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -132,28 +135,28 @@ public class WebSocketMobileServer {
|
|
//从set中删除
|
|
//从set中删除
|
|
subOnlineCount();
|
|
subOnlineCount();
|
|
//判断是否是正常退出
|
|
//判断是否是正常退出
|
|
- Date now = new Date();
|
|
|
|
- //大于等于超时时间,说明规定时间内都没有通信,非正常退出,因为期间会有心跳更新updateTime
|
|
|
|
- if ((now.getTime() - this.updateTime) / 1000 >= SystemConstant.WEBSOCKET_MAX_TIME_OUT / 1000) {
|
|
|
|
- Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
|
- MonitorVideoSourceEnum source = null;
|
|
|
|
- if (Objects.nonNull(objectMap.get(SystemConstant.MONITOR_LIVE_URL_ + MonitorVideoSourceEnum.MOBILE_FIRST.name()))) {
|
|
|
|
- source = MonitorVideoSourceEnum.MOBILE_FIRST;
|
|
|
|
- } else if (Objects.nonNull(objectMap.get(SystemConstant.MONITOR_LIVE_URL_ + MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
|
|
|
|
- source = MonitorVideoSourceEnum.MOBILE_SECOND;
|
|
|
|
- }
|
|
|
|
- objectMap.put(SystemConstant.MONITOR_STATUS_ + source.name(), MonitorStatusSourceEnum.STOP);
|
|
|
|
- redisUtil.setForHash(RedisKeyHelper.examRecordCacheKey(recordId), objectMap);
|
|
|
|
- ConcurrentHashMap<Long, WebSocketOeServer> webSocketMap = WebSocketOeServer.getWebSocketMap();
|
|
|
|
- if (Objects.nonNull(webSocketMap.get(recordId))) {
|
|
|
|
- WebSocketOeServer webSocketOeServer = webSocketMap.get(recordId);
|
|
|
|
- Map map = new HashMap<>();
|
|
|
|
- map.put(SystemConstant.RECORD_ID, recordId);
|
|
|
|
- map.put("monitorVideoSource", source.name());
|
|
|
|
- WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.MOBILE_MONITOR_STOP.name(), map);
|
|
|
|
- webSocketOeServer.sendMessage(websocketDto);
|
|
|
|
- }
|
|
|
|
|
|
+// Date now = new Date();
|
|
|
|
+// //大于等于超时时间,说明规定时间内都没有通信,非正常退出,因为期间会有心跳更新updateTime
|
|
|
|
+// if ((now.getTime() - this.updateTime) / 1000 >= SystemConstant.WEBSOCKET_MAX_TIME_OUT / 1000) {
|
|
|
|
+ Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
|
+ MonitorVideoSourceEnum source = null;
|
|
|
|
+ if (Objects.nonNull(objectMap.get(SystemConstant.MONITOR_LIVE_URL_ + MonitorVideoSourceEnum.MOBILE_FIRST.name()))) {
|
|
|
|
+ source = MonitorVideoSourceEnum.MOBILE_FIRST;
|
|
|
|
+ } else if (Objects.nonNull(objectMap.get(SystemConstant.MONITOR_LIVE_URL_ + MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
|
|
|
|
+ source = MonitorVideoSourceEnum.MOBILE_SECOND;
|
|
|
|
+ }
|
|
|
|
+ objectMap.put(SystemConstant.MONITOR_STATUS_ + source.name(), MonitorStatusSourceEnum.STOP);
|
|
|
|
+ redisUtil.setForHash(RedisKeyHelper.examRecordCacheKey(recordId), objectMap);
|
|
|
|
+ ConcurrentHashMap<Long, WebSocketOeServer> webSocketMap = WebSocketOeServer.getWebSocketMap();
|
|
|
|
+ if (Objects.nonNull(webSocketMap.get(recordId))) {
|
|
|
|
+ WebSocketOeServer webSocketOeServer = webSocketMap.get(recordId);
|
|
|
|
+ Map map = new HashMap<>();
|
|
|
|
+ map.put(SystemConstant.RECORD_ID, recordId);
|
|
|
|
+ map.put("monitorVideoSource", source.name());
|
|
|
|
+ WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.MOBILE_MONITOR_STOP.name(), map);
|
|
|
|
+ webSocketOeServer.sendMessage(websocketDto);
|
|
}
|
|
}
|
|
|
|
+// }
|
|
}
|
|
}
|
|
log.info("用户退出:{},当前在线人数为:{},updateTime:{}", this.sessionId, getOnlineCount(), this.updateTime);
|
|
log.info("用户退出:{},当前在线人数为:{},updateTime:{}", this.sessionId, getOnlineCount(), this.updateTime);
|
|
}
|
|
}
|