|
|
@@ -11,8 +11,10 @@ import com.yhlxj.netty.websocket.starter.annotations.*;
|
|
|
import com.yhlxj.netty.websocket.starter.socket.Session;
|
|
|
import io.netty.handler.codec.http.HttpHeaders;
|
|
|
import io.netty.handler.timeout.IdleStateEvent;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
@@ -22,8 +24,10 @@ import java.util.concurrent.ConcurrentMap;
|
|
|
* @author chan
|
|
|
* @date 2024-09-06 22:39
|
|
|
*/
|
|
|
-@WsServerEndpoint(value = "/ws/{userToken}/{taskId}")
|
|
|
+@Component
|
|
|
+@WsServerEndpoint(value = "/ws/midjourney/{userToken}/{taskId}")
|
|
|
@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
public class SocketServer {
|
|
|
|
|
|
private static ConcurrentMap<String, Set<Session>> sessionPool = new ConcurrentHashMap<>();
|
|
|
@@ -31,8 +35,7 @@ public class SocketServer {
|
|
|
|
|
|
private static final String ADMIN = "yhlxj";
|
|
|
|
|
|
- //@Autowired
|
|
|
- private MidjourneyService midjourneyService;
|
|
|
+ private final MidjourneyService midjourneyService;
|
|
|
|
|
|
@HandshakeBefore
|
|
|
public void handshakeBefore(HttpHeaders headers,@PathParam String userid) {
|
|
|
@@ -105,7 +108,6 @@ public class SocketServer {
|
|
|
|
|
|
//根据子类型进行处理
|
|
|
if (WsMessageTypeEnum.getMessageType(body.getStr("type")) == WsMessageTypeEnum.CLIENT_TASK_ID) { //
|
|
|
- MidjourneyService midjourneyService = SpringCtxUtils.getBean(MidjourneyService.class);
|
|
|
MidjourneyUserConversation conversation = midjourneyService.getConversationById(body.getStr("taskId"));
|
|
|
session.sendText(packMsg(WsMessageTypeEnum.SERVER_TASK_INFO, new JSONObject(conversation)));
|
|
|
} else {
|
|
|
@@ -173,8 +175,8 @@ public class SocketServer {
|
|
|
sendMessage(packMsg(typeEnum, message), userToken);
|
|
|
}
|
|
|
|
|
|
- public static void sendMessage(String message,String userToken){
|
|
|
- Set<Session> sessions = sessionPool.get(userToken);
|
|
|
+ public static void sendMessage(String message,String userId){
|
|
|
+ Set<Session> sessions = sessionPool.get(userId);
|
|
|
if (CollectionUtil.isNotEmpty(sessions)) {
|
|
|
sessions.forEach((session)->{
|
|
|
session.sendText(message);
|