fix: fixed bugs for runtime application
This commit is contained in:
@@ -15,6 +15,7 @@ public class CommandDispatcher {
|
||||
private final Typing typingCommand;
|
||||
private final Heartbeat heartbeatCommand;
|
||||
private final SystemNotify systemNotifyCommand;
|
||||
private final PersonalNotify personalNotifyCommand;
|
||||
|
||||
public void dispatch(JSONObject msg) throws IOException {
|
||||
String cmd = msg.getString("cmd");
|
||||
@@ -25,6 +26,7 @@ public class CommandDispatcher {
|
||||
case "TYPING" -> typingCommand.handle(msg);
|
||||
case "HEARTBEAT" -> heartbeatCommand.handle(msg);
|
||||
case "SYSTEM_NOTIFY" -> systemNotifyCommand.handle(msg);
|
||||
case "PERSONAL_NOTIFY" -> personalNotifyCommand.handle(msg);
|
||||
|
||||
default -> {
|
||||
System.err.println("Unknown command: " + cmd);
|
||||
|
||||
@@ -16,6 +16,9 @@ public class Message implements BaseCommandHandler {
|
||||
|
||||
@Override
|
||||
public void handle(JSONObject msg) throws IOException {
|
||||
/*
|
||||
TODO: 这里需要处理如果目标用户不在线,如何去完成消息的存储
|
||||
*/
|
||||
String to = msg.getString("to");
|
||||
sessionManager.sendToUser(Integer.valueOf(to), msg.toJSONString());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package xin.merlin.myplayerbackend.utils.websocket.command.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xin.merlin.myplayerbackend.utils.websocket.WebSocketSessionManager;
|
||||
import xin.merlin.myplayerbackend.utils.websocket.command.BaseCommandHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PersonalNotify implements BaseCommandHandler {
|
||||
|
||||
private final WebSocketSessionManager sessionManager;
|
||||
|
||||
@Override
|
||||
public void handle(JSONObject msg) throws IOException {
|
||||
String to = msg.getString("to");
|
||||
sessionManager.sendToUser(Integer.valueOf(to), msg.toJSONString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user