zhaowenyu
2026-02-27 b5c022295a2d678edff3f54d9ee10e2fa1515c2d
ard-sample/src/main/java/com/ard/sample/component/websocket/enums/MessageType.java
@@ -5,6 +5,10 @@
    STATUS("status"),
    CONTROL("control"),
    PROGRESS("progress"),
    LIVESTREAM("livestream"),
    LIVESTATUS("livestatus"),
    PING("ping"), // 新增心跳请求
    PONG("pong"), // 新增心跳响应
    ALL("all");
    private final String type;
@@ -17,12 +21,19 @@
        return type;
    }
    public static MessageType fromString(String type) {
    public static boolean fromString(String type) {
        // 遍历MessageType枚举的所有值
        for (MessageType messageType : MessageType.values()) {
            // 如果当前枚举值的type属性与传入的type字符串忽略大小写相等
            if (messageType.type.equalsIgnoreCase(type)) {
                return messageType;
                // 返回当前枚举值
                //return messageType;
                return true;
            }
        }
        throw new IllegalArgumentException("Unknown message type: " + type);
        // 如果遍历完所有枚举值都没有找到匹配的,则抛出异常
        //throw new IllegalArgumentException("Unknown message type: " + type);
        return false;
    }
}