|
@@ -1,18 +1,14 @@
|
|
|
package com.ym.mec.teacher.handler;
|
|
|
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
-import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.security.core.Authentication;
|
|
|
-import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.socket.*;
|
|
|
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
|
|
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
@@ -26,27 +22,19 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
|
|
|
private final Map<String, WebSocketSession> clients = new ConcurrentHashMap<>();
|
|
|
|
|
|
- @Autowired
|
|
|
- private SysUserFeignService sysUserFeignService;
|
|
|
-
|
|
|
public WebSocketHandler() {
|
|
|
super();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
|
|
- Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
- SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
- if(Objects.isNull(sysUser)){
|
|
|
- LOGGER.error("用户登录信息异常");
|
|
|
- }
|
|
|
- LOGGER.info("有新的客户端上线: {}", authentication.getPrincipal());
|
|
|
+ LOGGER.info("{}上线", session.getPrincipal().getName());
|
|
|
super.afterConnectionEstablished(session);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
- LOGGER.info("{}: {}", SecurityContextHolder.getContext().getAuthentication().getPrincipal(), message);
|
|
|
+ public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
|
|
+ LOGGER.info("{}: {}", session.getPrincipal().getName(), message.getPayload());
|
|
|
super.handleMessage(session, message);
|
|
|
}
|
|
|
|
|
@@ -76,7 +64,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
@Override
|
|
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
|
|
|
super.afterConnectionClosed(session, status);
|
|
|
- LOGGER.info("{}离线", SecurityContextHolder.getContext().getAuthentication().getPrincipal());
|
|
|
+ LOGGER.info("{}离线", session.getPrincipal().getName());
|
|
|
}
|
|
|
|
|
|
@Override
|