|
|
@@ -1,15 +1,14 @@
|
|
|
package org.thyy.socket.config;
|
|
|
|
|
|
-import lombok.Getter;
|
|
|
+import cn.hutool.core.text.StrFormatter;
|
|
|
import org.springframework.web.socket.CloseStatus;
|
|
|
|
|
|
/**
|
|
|
* 3000 ~ 4000 之间
|
|
|
*/
|
|
|
-@Getter
|
|
|
public enum CloseCodes {
|
|
|
|
|
|
- EDITING_IN_PROGRESS(3001, "还有人在编辑无法连接"),
|
|
|
+ EDITING_IN_PROGRESS(3001, "用户{}正在编辑,无法连接服务器。"),
|
|
|
|
|
|
KICKING_PEOPLE(3002, "已有医生在踢人,无法操作。"),
|
|
|
|
|
|
@@ -17,10 +16,21 @@ public enum CloseCodes {
|
|
|
|
|
|
FORCED_KICK_OUT(3004, "其他用户强制踢出");
|
|
|
|
|
|
+ private final Integer code;
|
|
|
+ private final String reason;
|
|
|
private final CloseStatus status;
|
|
|
|
|
|
CloseCodes(int code, String reason) {
|
|
|
- this.status = new CloseStatus(code, reason);
|
|
|
+ this.code = code;
|
|
|
+ this.reason = reason;
|
|
|
+ this.status = new CloseStatus(code);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CloseStatus getStrFormatterStatus(Object... values) {
|
|
|
+ if (values == null || values.length == 0) {
|
|
|
+ return status;
|
|
|
+ }
|
|
|
+ return new CloseStatus(this.code, StrFormatter.format(this.reason, values));
|
|
|
}
|
|
|
|
|
|
}
|