zhaowenyu
2025-12-03 97aed6e19bac0fefaaf0270ba94492228ebf0bb1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.ard.sample.component.websocket.enums;
 
public enum MessageType {
    STATE("state"),
    STATUS("status"),
    CONTROL("control"),
    PROGRESS("progress"),
    LIVESTREAM("livestream"),
    PING("ping"), // 新增心跳请求
    PONG("pong"), // 新增心跳响应
    ALL("all");
 
    private final String type;
 
    MessageType(String type) {
        this.type = type;
    }
 
    public String getType() {
        return type;
    }
 
    public static boolean fromString(String type) {
        // 遍历MessageType枚举的所有值
        for (MessageType messageType : MessageType.values()) {
            // 如果当前枚举值的type属性与传入的type字符串忽略大小写相等
            if (messageType.type.equalsIgnoreCase(type)) {
                // 返回当前枚举值
                //return messageType;
                return true;
            }
        }
        // 如果遍历完所有枚举值都没有找到匹配的,则抛出异常
        //throw new IllegalArgumentException("Unknown message type: " + type);
        return false;
    }
 
}