diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/ScriptProperties.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/ScriptProperties.java index bd4b8a3..97bcf57 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/ScriptProperties.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/ScriptProperties.java @@ -18,14 +18,14 @@ import lombok.Setter; public class ScriptProperties { @Schema(title = "是否启用", description = "是否启用") - private Boolean enabled; + private Boolean enabled; @Schema(title = "重启系统", description = "重启系统") - private String systemReboot; + private String systemReboot; @Schema(title = "关闭系统", description = "关闭系统") - private String systemShutdown; + private String systemShutdown; @Schema(title = "重启平台", description = "重启平台") - private String platformReboot; + private String platformReboot; @Schema(title = "关闭平台", description = "关闭平台") - private String platformShutdown; - + private String platformShutdown; + } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/SocketProperties.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/SocketProperties.java index 77a5259..8b5f461 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/SocketProperties.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/SocketProperties.java @@ -18,7 +18,7 @@ import lombok.Setter; public class SocketProperties { /** - * 机密策略 + * 加密策略 * * @author acgist */ @@ -44,30 +44,30 @@ public class SocketProperties { } @Schema(title = "是否启用", description = "是否启用") - private Boolean enabled; + private Boolean enabled; @Schema(title = "监听地址", description = "监听地址") - private String host; + private String host; @Schema(title = "监听端口", description = "监听端口") - private Integer port; + private Integer port; @Schema(title = "加密策略", description = "加密策略") private Encrypt encrypt; @Schema(title = "加密密钥", description = "加密密钥:为空自动生成") private String encryptSecret; @Schema(title = "超时时间", description = "超时时间") - private Long timeout; + private Long timeout; @Schema(title = "队列长度", description = "队列长度") - private Integer queueSize; + private Integer queueSize; @Schema(title = "最小线程数量", description = "最小线程数量") - private Integer minThread; + private Integer minThread; @Schema(title = "最大线程数量", description = "最大线程数量") - private Integer maxThread; + private Integer maxThread; @Schema(title = "线程池的前缀", description = "线程池的前缀") - private String threadNamePrefix; + private String threadNamePrefix; @Schema(title = "线程销毁时间", description = "线程销毁时间") - private Long keepAliveTime; + private Long keepAliveTime; @Schema(title = "缓冲大小", description = "缓冲大小") - private Integer bufferSize; + private Integer bufferSize; @Schema(title = "最大缓冲大小", description = "最大缓冲大小") private Integer maxBufferSize; - + } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/TaoyaoProperties.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/TaoyaoProperties.java index 5e52fae..cf90a3c 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/TaoyaoProperties.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/TaoyaoProperties.java @@ -16,16 +16,16 @@ import lombok.Setter; @Schema(title = "平台配置", description = "平台配置") @ConfigurationProperties(prefix = "taoyao") public class TaoyaoProperties { - - @Schema(title = "项目地址", description = "项目地址") - private String url; - @Schema(title = "项目名称", description = "项目名称") - private String name; - @Schema(title = "项目版本", description = "项目版本") - private String version; - @Schema(title = "项目描述", description = "项目描述") - private String description; - @Schema(title = "超时时间", description = "超时时间") - private Long timeout; + + @Schema(title = "项目地址", description = "项目地址") + private String url; + @Schema(title = "项目名称", description = "项目名称") + private String name; + @Schema(title = "项目版本", description = "项目版本") + private String version; + @Schema(title = "项目描述", description = "项目描述") + private String description; + @Schema(title = "超时时间", description = "超时时间") + private Long timeout; } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/WebrtcProperties.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/WebrtcProperties.java index 1f63195..caa93e8 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/WebrtcProperties.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/config/WebrtcProperties.java @@ -1,7 +1,6 @@ package com.acgist.taoyao.boot.config; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,33 +21,31 @@ import lombok.Setter; @ConfigurationProperties(prefix = "taoyao.webrtc") public class WebrtcProperties { - @Schema(title = "是否加密", description = "是否加密") + @Schema(title = "是否终端加密", description = "是否终端加密") private Boolean encrypt; - @Schema(title = "STUN服务器", description = "STUN服务器") - private WebrtcStunProperties[] stun; - @Schema(title = "TURN服务器", description = "TURN服务器") - private WebrtcTurnProperties[] turn; - + @Schema(title = "STUN服务器", description = "STUN服务器") + private WebrtcStunProperties[] stun; + @Schema(title = "TURN服务器", description = "TURN服务器") + private WebrtcTurnProperties[] turn; + @Schema(title = "IceServers", description = "IceServers") public List> getIceServers() { final List> list = new ArrayList<>(); if(this.stun != null) { for (WebrtcStunProperties stun : this.stun) { - final Map map = new HashMap<>(); - map.put(Constant.URLS, stun.getAddress()); - list.add(map); + list.add(Map.of(Constant.URLS, stun.getAddress())); } } if(this.turn != null) { for (WebrtcTurnProperties turn : this.turn) { - final Map map = new HashMap<>(); - map.put(Constant.URLS, turn.getAddress()); - map.put(Constant.USERNAME, turn.getUsername()); - map.put(Constant.CREDENTIAL, turn.getPassword()); - list.add(map); + list.add(Map.of( + Constant.URLS, turn.getAddress(), + Constant.USERNAME, turn.getUsername(), + Constant.CREDENTIAL, turn.getPassword() + )); } } return list; } - + } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/BootAutoConfiguration.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/BootAutoConfiguration.java index 5b6132e..60949aa 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/BootAutoConfiguration.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/BootAutoConfiguration.java @@ -1,7 +1,6 @@ package com.acgist.taoyao.boot.configuration; import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; import java.util.Timer; import java.util.TimerTask; import java.util.stream.Collectors; @@ -45,8 +44,8 @@ import org.springframework.web.servlet.NoHandlerFoundException; import com.acgist.taoyao.boot.config.FfmpegProperties; import com.acgist.taoyao.boot.config.IdProperties; -import com.acgist.taoyao.boot.config.RewriteProperties; import com.acgist.taoyao.boot.config.MediaProperties; +import com.acgist.taoyao.boot.config.RewriteProperties; import com.acgist.taoyao.boot.config.ScriptProperties; import com.acgist.taoyao.boot.config.SecurityProperties; import com.acgist.taoyao.boot.config.SocketProperties; @@ -70,6 +69,7 @@ import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.validation.ConstraintViolationException; import jakarta.validation.ValidationException; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; /** @@ -95,18 +95,13 @@ import lombok.extern.slf4j.Slf4j; RewriteProperties.class, SecurityProperties.class, }) +@RequiredArgsConstructor public class BootAutoConfiguration { - private final FfmpegProperties ffmpegProperties; - private final TaoyaoProperties taoyaoProperties; + private final FfmpegProperties ffmpegProperties; + private final TaoyaoProperties taoyaoProperties; private final ApplicationContext applicationContext; - public BootAutoConfiguration(FfmpegProperties ffmpegProperties, TaoyaoProperties taoyaoProperties, ApplicationContext applicationContext) { - this.ffmpegProperties = ffmpegProperties; - this.taoyaoProperties = taoyaoProperties; - this.applicationContext = applicationContext; - } - @Bean @ConditionalOnMissingBean public IdService idService(IdProperties idProperties) { @@ -148,8 +143,8 @@ public class BootAutoConfiguration { @Bean public CommandLineRunner successCommandLineRunner( - TaskExecutor taskExecutor, - TaoyaoProperties taoyaoProperties, + TaskExecutor taskExecutor, + TaoyaoProperties taoyaoProperties, RewriteProperties rewriteProperties ) { return new OrderedCommandLineRunner() { @@ -164,10 +159,9 @@ public class BootAutoConfiguration { @PostConstruct public void init() { - final Runtime runtime = Runtime.getRuntime(); - final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); - final String maxMemory = FileUtils.formatSize(runtime.maxMemory()); - final String freeMemory = FileUtils.formatSize(runtime.freeMemory()); + final Runtime runtime = Runtime.getRuntime(); + final String maxMemory = FileUtils.formatSize(runtime.maxMemory()); + final String freeMemory = FileUtils.formatSize(runtime.freeMemory()); final String totalMemory = FileUtils.formatSize(runtime.totalMemory()); log.info("操作系统架构:{}", System.getProperty("os.arch")); log.info("操作系统名称:{}", System.getProperty("os.name")); @@ -178,7 +172,7 @@ public class BootAutoConfiguration { log.info("Java库目录:{}", System.getProperty("java.library.path")); log.info("ClassPath:{}", System.getProperty("java.class.path")); log.info("虚拟机名称:{}", System.getProperty("java.vm.name")); - log.info("虚拟机参数:{}", runtimeMXBean.getInputArguments().stream().collect(Collectors.joining(" "))); + log.info("虚拟机参数:{}", ManagementFactory.getRuntimeMXBean().getInputArguments().stream().collect(Collectors.joining(" "))); log.info("虚拟机最大内存:{}", maxMemory); log.info("虚拟机空闲内存:{}", freeMemory); log.info("虚拟机已用内存:{}", totalMemory); diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/SpringDocAutoConfiguration.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/SpringDocAutoConfiguration.java index f025526..48489de 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/SpringDocAutoConfiguration.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/SpringDocAutoConfiguration.java @@ -19,6 +19,7 @@ import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; +import lombok.RequiredArgsConstructor; /** * 文档自动配置 @@ -28,6 +29,7 @@ import io.swagger.v3.oas.models.security.SecurityScheme; @Profile({ "dev", "sit" }) @AutoConfiguration @ConditionalOnClass(OpenAPI.class) +@RequiredArgsConstructor public class SpringDocAutoConfiguration { @Value("${server.port:8888}") @@ -37,95 +39,91 @@ public class SpringDocAutoConfiguration { private final TaoyaoProperties taoyaoProperties; - public SpringDocAutoConfiguration(TaoyaoProperties taoyaoProperties) { - this.taoyaoProperties = taoyaoProperties; + @Bean + public GroupedOpenApi signalApi() { + return GroupedOpenApi.builder() + .group("signal") + .displayName("信令") + .packagesToScan("com.acgist.taoyao.signal") + .build(); } - - @Bean - public GroupedOpenApi signalApi() { - return GroupedOpenApi.builder() - .group("signal") - .displayName("信令") - .packagesToScan("com.acgist.taoyao.signal") - .build(); - } - - @Bean - public GroupedOpenApi taoyaoApi() { - return GroupedOpenApi.builder() - .group("taoyao") - .displayName("桃夭") - .packagesToScan("com.acgist.taoyao") - .build(); - } - - @Bean - @ConditionalOnMissingBean - public OpenAPI openAPI() { - return new OpenAPI() + + @Bean + public GroupedOpenApi taoyaoApi() { + return GroupedOpenApi.builder() + .group("taoyao") + .displayName("桃夭") + .packagesToScan("com.acgist.taoyao") + .build(); + } + + @Bean + @ConditionalOnMissingBean + public OpenAPI openAPI() { + return new OpenAPI() // .servers(null) - .info(this.buildInfo()) - .security(this.buildSecurity()) - .components(this.buildComponents()); - } + .info(this.buildInfo()) + .security(this.buildSecurity()) + .components(this.buildComponents()); + } - /** - * @return 基本信息 - */ - private Info buildInfo() { - return new Info() - .contact(this.buildContact()) - .license(this.buildLicense()) - .title(this.taoyaoProperties.getName()) - .version(this.taoyaoProperties.getVersion()) - .description(this.taoyaoProperties.getDescription()); - } - - /** - * @return 联系方式 - */ - private Contact buildContact() { - return new Contact() - .url(this.taoyaoProperties.getUrl()) - .name(this.taoyaoProperties.getName()); - } + /** + * @return 基本信息 + */ + private Info buildInfo() { + return new Info() + .contact(this.buildContact()) + .license(this.buildLicense()) + .title(this.taoyaoProperties.getName()) + .version(this.taoyaoProperties.getVersion()) + .description(this.taoyaoProperties.getDescription()); + } + + /** + * @return 联系方式 + */ + private Contact buildContact() { + return new Contact() + .url(this.taoyaoProperties.getUrl()) + .name(this.taoyaoProperties.getName()); + } - /** - * @return 开源信息 - */ - private License buildLicense() { - return new License() - .url("https://www.apache.org/licenses/LICENSE-2.0.html") - .name("Apache 2.0"); - } + /** + * @return 开源信息 + */ + private License buildLicense() { + return new License() + .url("https://www.apache.org/licenses/LICENSE-2.0.html") + .name("Apache 2.0"); + } - /** - * @return 安全授权 - */ - private List buildSecurity() { - return List.of( - new SecurityRequirement() - .addList(this.scheme) - ); - } - - /** - * @return 安全授权 - */ - private Components buildComponents() { - return new Components() - .addSecuritySchemes(this.scheme, this.buildSecurityScheme()); - } - - /** - * @return 授权模式 - */ - private SecurityScheme buildSecurityScheme() { - return new SecurityScheme() - .name(this.scheme) - .scheme(this.scheme) - .in(SecurityScheme.In.HEADER) - .type(SecurityScheme.Type.HTTP); - } - + /** + * @return 安全授权 + */ + private List buildSecurity() { + return List.of( + new SecurityRequirement() + .addList(this.scheme) + ); + } + + /** + * @return 安全授权 + */ + private Components buildComponents() { + return new Components() + .addSecuritySchemes(this.scheme, this.buildSecurityScheme()); + } + + /** + * @return 授权模式 + */ + private SecurityScheme buildSecurityScheme() { + return new SecurityScheme() + .name(this.scheme) + .scheme(this.scheme) + .in(SecurityScheme.In.HEADER) + .type(SecurityScheme.Type.HTTP); + } + } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/WebMvcConfigurerAutoConfiguration.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/WebMvcConfigurerAutoConfiguration.java index 94a35e5..e67c118 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/WebMvcConfigurerAutoConfiguration.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/configuration/WebMvcConfigurerAutoConfiguration.java @@ -7,41 +7,32 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import com.acgist.taoyao.boot.interceptor.InterceptorAdapter; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; /** * MVC自动配置 * - * TODO:ErrorPageRegistrar拦截400错误https://localhost:8888/?\%3E%3C - * * @author acgist */ @Slf4j @AutoConfiguration +@RequiredArgsConstructor public class WebMvcConfigurerAutoConfiguration implements WebMvcConfigurer { - - private final ApplicationContext applicationContext; - - public WebMvcConfigurerAutoConfiguration(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; - } - - @Override - public void addInterceptors(InterceptorRegistry registry) { - this.applicationContext.getBeansOfType(InterceptorAdapter.class).entrySet().stream() - .sorted((a, z) -> a.getValue().compareTo(z.getValue())) - .forEach(entry -> { - final InterceptorAdapter value = entry.getValue(); - if(log.isDebugEnabled()) { - log.debug("注册MVC拦截器:{} - {}", String.format("%-32s", entry.getKey()), value.name()); - } - registry.addInterceptor(value).addPathPatterns(value.pathPattern()); - }); - } -// @Override -// public void addCorsMappings(CorsRegistry registry) { -// WebMvcConfigurer.super.addCorsMappings(registry); -// } + private final ApplicationContext applicationContext; + + @Override + public void addInterceptors(InterceptorRegistry registry) { + this.applicationContext.getBeansOfType(InterceptorAdapter.class).entrySet().stream() + .sorted((a, z) -> a.getValue().compareTo(z.getValue())) + .forEach(entry -> { + final InterceptorAdapter value = entry.getValue(); + if(log.isDebugEnabled()) { + log.debug("注册MVC拦截器:{} - {}", String.format("%-32s", entry.getKey()), value.name()); + } + registry.addInterceptor(value).addPathPatterns(value.pathPattern()); + }); + } } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/controller/TaoyaoControllerAdvice.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/controller/TaoyaoControllerAdvice.java index dffe949..4363f8c 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/controller/TaoyaoControllerAdvice.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/controller/TaoyaoControllerAdvice.java @@ -14,6 +14,8 @@ import jakarta.servlet.http.HttpServletResponse; /** * 统一异常处理 * + * 不能处理:https://localhost:8888/?\%3E%3C + * * @author acgist */ @Tag(name = "统一异常处理", description = "全局统一异常处理") @@ -21,9 +23,9 @@ import jakarta.servlet.http.HttpServletResponse; public class TaoyaoControllerAdvice { @Operation(summary = "统一异常处理", description = "全局统一异常处理") - @ExceptionHandler(Exception.class) - public Message exception(Exception e, HttpServletRequest request, HttpServletResponse response) { - return ErrorUtils.message(e, request, response); - } + @ExceptionHandler(Exception.class) + public Message exception(Exception e, HttpServletRequest request, HttpServletResponse response) { + return ErrorUtils.message(e, request, response); + } } \ No newline at end of file diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/controller/TaoyaoErrorController.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/controller/TaoyaoErrorController.java index 145ca34..ce792d7 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/controller/TaoyaoErrorController.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/controller/TaoyaoErrorController.java @@ -21,10 +21,10 @@ import jakarta.servlet.http.HttpServletResponse; @RestController public class TaoyaoErrorController implements ErrorController { - @Operation(summary = "统一错误页面", description = "全局统一错误页面") - @RequestMapping(value = ErrorUtils.ERROR_PATH) - public Message index(HttpServletRequest request, HttpServletResponse response) { - return ErrorUtils.message(request, response); - } + @Operation(summary = "统一错误页面", description = "全局统一错误页面") + @RequestMapping(value = ErrorUtils.ERROR_PATH) + public Message index(HttpServletRequest request, HttpServletResponse response) { + return ErrorUtils.message(request, response); + } } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/interceptor/InterceptorAdapter.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/interceptor/InterceptorAdapter.java index d220a1d..a913fcb 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/interceptor/InterceptorAdapter.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/interceptor/InterceptorAdapter.java @@ -10,19 +10,19 @@ import org.springframework.web.servlet.HandlerInterceptor; */ public abstract class InterceptorAdapter implements Ordered, Comparable, HandlerInterceptor { - /** - * @return 名称 - */ - public abstract String name(); - - /** - * @return 拦截地址 - */ - public abstract String[] pathPattern(); - - @Override - public int compareTo(InterceptorAdapter target) { - return Integer.compare(this.getOrder(), target.getOrder()); - } - + /** + * @return 名称 + */ + public abstract String name(); + + /** + * @return 拦截地址 + */ + public abstract String[] pathPattern(); + + @Override + public int compareTo(InterceptorAdapter target) { + return Integer.compare(this.getOrder(), target.getOrder()); + } + } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/Header.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/Header.java index c1cbf90..b2f0c6a 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/Header.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/Header.java @@ -22,27 +22,27 @@ import lombok.Setter; @AllArgsConstructor public class Header implements Cloneable, Serializable { - private static final long serialVersionUID = 1L; - - /** - * 消息版本 - */ - @Schema(title = "消息版本", description = "消息版本") - private String v; - /** - * 消息标识 - */ - @Schema(title = "消息标识", description = "消息标识") - private Long id; - /** - * 信令标识 - */ - @Schema(title = "信令标识", description = "信令标识") - private String signal; - - @Override - public Header clone() { - return new Header(this.v, this.id, this.signal); - } - + private static final long serialVersionUID = 1L; + + /** + * 消息版本 + */ + @Schema(title = "消息版本", description = "消息版本") + private String v; + /** + * 消息标识 + */ + @Schema(title = "消息标识", description = "消息标识") + private Long id; + /** + * 信令标识 + */ + @Schema(title = "信令标识", description = "信令标识") + private String signal; + + @Override + public Header clone() { + return new Header(this.v, this.id, this.signal); + } + } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/Message.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/Message.java index 6caa3af..b90b868 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/Message.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/Message.java @@ -25,36 +25,36 @@ import lombok.Setter; @JsonIncludeProperties(value = { "code", "message", "header", "body" }) public class Message implements Cloneable, Serializable { - private static final long serialVersionUID = 1L; - + private static final long serialVersionUID = 1L; + /** * 成功标识 */ public static final String CODE_0000 = "0000"; - /** - * 状态编码 - */ - @Schema(title = "状态编码", description = "状态编码") - private String code; - /** - * 状态描述 - */ - @Schema(title = "状态描述", description = "状态描述") - private String message; - /** - * 消息头部 - */ - @Schema(title = "消息头部", description = "消息头部") - private Header header; - /** - * 消息主体 - */ - @Schema(title = "消息主体", description = "消息主体") - private Object body; - + /** + * 状态编码 + */ + @Schema(title = "状态编码", description = "状态编码") + private String code; + /** + * 状态描述 + */ + @Schema(title = "状态描述", description = "状态描述") + private String message; + /** + * 消息头部 + */ + @Schema(title = "消息头部", description = "消息头部") + private Header header; + /** + * 消息主体 + */ + @Schema(title = "消息主体", description = "消息主体") + private Object body; + public Message() { - // 默认消息都是成功 + // 消息默认都是成功 final MessageCode messageCode = MessageCode.CODE_0000; this.code = messageCode.getCode(); this.message = messageCode.getMessage(); @@ -66,99 +66,99 @@ public class Message implements Cloneable, Serializable { this.header = header; this.body = body; } - - /** - * @return 成功消息 - */ - public static final Message success() { - return Message.success(null); - } + + /** + * @return 成功消息 + */ + public static final Message success() { + return Message.success(null); + } - /** - * @param body 消息主体 - * - * @return 成功消息 - */ - public static final Message success(Object body) { - final Message message = new Message(); - message.setCode(MessageCode.CODE_0000, null); - message.body = body; - return message; - } + /** + * @param body 消息主体 + * + * @return 成功消息 + */ + public static final Message success(Object body) { + final Message message = new Message(); + message.setCode(MessageCode.CODE_0000, null); + message.body = body; + return message; + } - /** - * @return 失败消息 - */ - public static final Message fail() { - return Message.fail(null, null, null); - } + /** + * @return 失败消息 + */ + public static final Message fail() { + return Message.fail(null, null, null); + } - /** - * @param messageCode 状态编码 - * - * @return 失败消息 - */ - public static final Message fail(MessageCode messageCode) { - return Message.fail(messageCode, null, null); - } + /** + * @param messageCode 状态编码 + * + * @return 失败消息 + */ + public static final Message fail(MessageCode messageCode) { + return Message.fail(messageCode, null, null); + } - /** - * @param messageCode 状态编码 - * @param body 消息主体 - * - * @return 失败消息 - */ - public static final Message fail(MessageCode messageCode, Object body) { - return Message.fail(messageCode, null, body); - } - - /** - * @param message 状态描述 - * - * @return 失败消息 - */ - public static final Message fail(String message) { - return Message.fail(null, message, null); - } - - /** - * @param message 状态描述 - * @param body 消息主体 - * - * @return 失败消息 - */ - public static final Message fail(String message, Object body) { - return Message.fail(null, message, body); - } - - /** - * @param messageCode 状态编码 - * @param message 状态描述 - * - * @return 失败消息 - */ - public static final Message fail(MessageCode messageCode, String message) { - return Message.fail(messageCode, message, null); - } + /** + * @param messageCode 状态编码 + * @param body 消息主体 + * + * @return 失败消息 + */ + public static final Message fail(MessageCode messageCode, Object body) { + return Message.fail(messageCode, null, body); + } + + /** + * @param message 状态描述 + * + * @return 失败消息 + */ + public static final Message fail(String message) { + return Message.fail(null, message, null); + } + + /** + * @param message 状态描述 + * @param body 消息主体 + * + * @return 失败消息 + */ + public static final Message fail(String message, Object body) { + return Message.fail(null, message, body); + } + + /** + * @param messageCode 状态编码 + * @param message 状态描述 + * + * @return 失败消息 + */ + public static final Message fail(MessageCode messageCode, String message) { + return Message.fail(messageCode, message, null); + } - /** - * @param messageCode 状态编码 - * @param message 状态描述 - * @param body 消息主体 - * - * @return 失败消息 - */ - public static final Message fail(MessageCode messageCode, String message, Object body) { - final Message failMessage = new Message(); - failMessage.setCode(messageCode == null ? MessageCode.CODE_9999 : messageCode, message); - failMessage.body = body; - return failMessage; - } + /** + * @param messageCode 状态编码 + * @param message 状态描述 + * @param body 消息主体 + * + * @return 失败消息 + */ + public static final Message fail(MessageCode messageCode, String message, Object body) { + final Message failMessage = new Message(); + failMessage.setCode(messageCode == null ? MessageCode.CODE_9999 : messageCode, message); + failMessage.body = body; + return failMessage; + } - @Override - public Message clone() { - return new Message(this.code, this.message, this.header.clone(), this.body); - } + @Override + public Message clone() { + return new Message(this.code, this.message, this.header.clone(), this.body); + } /** * @param messageCode 状态编码 @@ -178,23 +178,23 @@ public class Message implements Cloneable, Serializable { this.message = StringUtils.isEmpty(message) ? messageCode.getMessage() : message; return this; } - - /** - * 克隆消息排除消息主体 - * - * @return 克隆消息 - */ - public Message cloneWithoutBody() { - return new Message(this.code, this.message, this.header.clone(), null); - } - - /** - * @return 消息主体 - */ + + /** + * 克隆消息排除消息主体 + * + * @return 克隆消息 + */ + public Message cloneWithoutBody() { + return new Message(this.code, this.message, this.header.clone(), null); + } + + /** + * @return 消息主体 + */ @SuppressWarnings("unchecked") public T body() { - return (T) this.body; - } + return (T) this.body; + } /** * 注解不会自动生成 @@ -205,16 +205,9 @@ public class Message implements Cloneable, Serializable { this.code = code; } - /** - * @return 是否成功 - */ - public boolean isSuccess() { - return CODE_0000.equals(this.code); + @Override + public String toString() { + return JSONUtils.toJSON(this); } - - @Override - public String toString() { - return JSONUtils.toJSON(this); - } } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/MessageCode.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/MessageCode.java index 5d5f90c..19ea9c5 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/MessageCode.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/MessageCode.java @@ -14,78 +14,78 @@ import lombok.Getter; */ @Getter public enum MessageCode { - - // 成功 - CODE_0000("0000", 200, "成功"), - // 1xxx - CODE_1000("1000", 404, "未知接口"), - CODE_1001("1001", 400, "上次请求没有完成"), - CODE_1002("1002", 400, "数据格式错误"), - CODE_1003("1003", 400, "验签失败"), - // 2xxx - CODE_2000("2000", 500, "服务错误"), - CODE_2001("2001", 504, "服务超时"), - // 3xxx - CODE_3400("3400", 400, "请求错误"), - CODE_3401("3401", 401, "没有授权"), - CODE_3403("3403", 403, "请求拒绝"), - CODE_3404("3404", 404, "资源失效"), - CODE_3405("3405", 405, "请求方法错误"), - CODE_3406("3406", 406, "请求不可接受"), - CODE_3415("3415", 415, "请求资源类型错误"), - CODE_3500("3500", 500, "系统异常"), - CODE_3502("3502", 502, "服务无效"), - CODE_3503("3503", 503, "服务正在维护"), - CODE_3504("3504", 504, "服务超时"), - // 9999 - CODE_9999("9999", 500, "未知错误"); - - /** - * HTTP Status前缀 - */ - private static final String HTTP_STATUS = "3"; - - /** - * 状态编码 - */ - private final String code; - /** - * 状态数值(HTTP Status) - */ - private final Integer status; - /** - * 状态描述 - */ - private final String message; + + // 成功 + CODE_0000("0000", 200, "成功"), + // 1xxx + CODE_1000("1000", 404, "未知接口"), + CODE_1001("1001", 400, "上次请求没有完成"), + CODE_1002("1002", 400, "数据格式错误"), + CODE_1003("1003", 400, "验签失败"), + // 2xxx + CODE_2000("2000", 500, "服务错误"), + CODE_2001("2001", 504, "服务超时"), + // 3xxx + CODE_3400("3400", 400, "请求错误"), + CODE_3401("3401", 401, "没有授权"), + CODE_3403("3403", 403, "请求拒绝"), + CODE_3404("3404", 404, "资源失效"), + CODE_3405("3405", 405, "请求方法错误"), + CODE_3406("3406", 406, "请求不可接受"), + CODE_3415("3415", 415, "请求资源类型错误"), + CODE_3500("3500", 500, "系统异常"), + CODE_3502("3502", 502, "服务无效"), + CODE_3503("3503", 503, "服务正在维护"), + CODE_3504("3504", 504, "服务超时"), + // 9999 + CODE_9999("9999", 500, "未知错误"); + + /** + * HTTP Status前缀 + */ + private static final String HTTP_STATUS = "3"; + + /** + * 状态编码 + */ + private final String code; + /** + * 状态数值(HTTP Status) + */ + private final Integer status; + /** + * 状态描述 + */ + private final String message; - private MessageCode(String code, Integer status, String message) { - this.code = code; - this.status = status; - this.message = message; - } + private MessageCode(String code, Integer status, String message) { + this.code = code; + this.status = status; + this.message = message; + } - /** - * @param code 状态编码 - * - * @return 状态编码 - */ - public static final MessageCode of(String code) { - final MessageCode[] values = MessageCode.values(); - for (final MessageCode value : values) { - if (value.code.equals(code)) { - return value; - } - } - return CODE_9999; - } + /** + * @param code 状态编码 + * + * @return 状态编码 + */ + public static final MessageCode of(String code) { + final MessageCode[] values = MessageCode.values(); + for (final MessageCode value : values) { + if (value.code.equals(code)) { + return value; + } + } + return CODE_9999; + } - /** - * @param status HTTP Status - * - * @return 状态编码 - */ - public static final MessageCode of(Integer status) { - return MessageCode.of(HTTP_STATUS + status); - } - + /** + * @param status HTTP Status + * + * @return 状态编码 + */ + public static final MessageCode of(Integer status) { + return MessageCode.of(HTTP_STATUS + status); + } + } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/MessageCodeException.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/MessageCodeException.java index 8cb4bc1..e92c208 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/MessageCodeException.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/MessageCodeException.java @@ -14,67 +14,67 @@ import lombok.Getter; @Getter public class MessageCodeException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 状态编码 - */ - private final MessageCode messageCode; + /** + * 状态编码 + */ + private final MessageCode messageCode; - /** - * @param message 异常消息 - * - * @return 状态编码异常 - */ - public static final MessageCodeException of(String message) { - return of(null, null, message); - } - - /** - * @param t 异常 - * @param message 异常消息 - * - * @return 状态编码异常 - */ - public static final MessageCodeException of(Throwable t, String message) { - return of(t, null, message); - } - - /** - * @param messageCode 状态编码 - * @param message 异常消息 - * - * @return 状态编码异常 - */ - public static final MessageCodeException of(MessageCode messageCode, String message) { - return of(null, messageCode, message); - } - - /** - * @param t 异常 - * @param messageCode 状态编码 - * @param message 异常消息 - * - * @return 状态编码异常 - */ - public static final MessageCodeException of(Throwable t, MessageCode messageCode, String message) { - if(messageCode == null) { - messageCode = MessageCode.CODE_9999; - } - if(StringUtils.isEmpty(message)) { - message = Objects.isNull(t) ? messageCode.getMessage() : t.getMessage(); - } - return new MessageCodeException(t, messageCode, message); - } + /** + * @param message 异常消息 + * + * @return 状态编码异常 + */ + public static final MessageCodeException of(String message) { + return of(null, null, message); + } + + /** + * @param t 异常 + * @param message 异常消息 + * + * @return 状态编码异常 + */ + public static final MessageCodeException of(Throwable t, String message) { + return of(t, null, message); + } + + /** + * @param messageCode 状态编码 + * @param message 异常消息 + * + * @return 状态编码异常 + */ + public static final MessageCodeException of(MessageCode messageCode, String message) { + return of(null, messageCode, message); + } + + /** + * @param t 异常 + * @param messageCode 状态编码 + * @param message 异常消息 + * + * @return 状态编码异常 + */ + public static final MessageCodeException of(Throwable t, MessageCode messageCode, String message) { + if(messageCode == null) { + messageCode = MessageCode.CODE_9999; + } + if(StringUtils.isEmpty(message)) { + message = Objects.isNull(t) ? messageCode.getMessage() : t.getMessage(); + } + return new MessageCodeException(t, messageCode, message); + } - /** - * @param t 异常 - * @param messageCode 状态编码 - * @param message 异常消息 - */ - public MessageCodeException(Throwable t, MessageCode messageCode, String message) { - super(message, t); - this.messageCode = messageCode; - } + /** + * @param t 异常 + * @param messageCode 状态编码 + * @param message 异常消息 + */ + public MessageCodeException(Throwable t, MessageCode messageCode, String message) { + super(message, t); + this.messageCode = messageCode; + } } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/ModifyOptional.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/ModifyOptional.java deleted file mode 100644 index e422d90..0000000 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/model/ModifyOptional.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.acgist.taoyao.boot.model; - -import java.util.function.Supplier; - -/** - * 可修改的Optional - * - * @author acgist - */ -public final class ModifyOptional { - - /** - * 值 - */ - private T t; - /** - * 生产者 - */ - private Supplier supplier; - - private ModifyOptional(T t, Supplier supplier) { - this.t = t; - this.supplier = supplier; - } - - public static final ModifyOptional of(T t) { - return new ModifyOptional<>(t, null); - } - - public static final ModifyOptional of(Supplier supplier) { - return new ModifyOptional<>(null, supplier); - } - - /** - * @return 值 - */ - public T get() { - return this.t; - } - - /** - * @return 值 - */ - public T build() { - if(this.t != null) { - return this.t; - } - this.t = this.supplier.get(); - return this.t; - } - -} diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/service/IdService.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/service/IdService.java index 7993561..2b71897 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/service/IdService.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/service/IdService.java @@ -7,24 +7,24 @@ package com.acgist.taoyao.boot.service; */ public interface IdService { - /** - * 生成十六位的消息ID:ddHHmmss(8) + index(2) + xxxxxx(6) - * 只能用于生成消息ID:JS超过`Number.MAX_SAFE_INTEGER`丢失精度 - * - * @return ID - */ - long buildId(); - - /** - * @return 终端索引 - */ - long buildClientIndex(); - - /** - * 生成三十二位唯一ID - * - * @return ID - */ - String buildUuid(); - + /** + * 生成十六位的消息ID:ddHHmmss(8) + index(2) + xxxxxx(6) + * 只能用于生成消息ID:JS超过`Number.MAX_SAFE_INTEGER`丢失精度 + * + * @return ID + */ + long buildId(); + + /** + * @return 终端索引 + */ + long buildClientIndex(); + + /** + * 生成三十二位唯一ID + * + * @return ID + */ + String buildUuid(); + } diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/service/impl/IdServiceImpl.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/service/impl/IdServiceImpl.java index bfab30f..4ffcf39 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/service/impl/IdServiceImpl.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/service/impl/IdServiceImpl.java @@ -7,59 +7,59 @@ import com.acgist.taoyao.boot.config.IdProperties; import com.acgist.taoyao.boot.service.IdService; public class IdServiceImpl implements IdService { - - public IdServiceImpl(IdProperties idProperties) { - this.index = 0; - this.serverIndex = idProperties.getServerIndex(); - this.maxIndex = idProperties.getMaxIndex(); - this.clientIndex = idProperties.getMinClientIndex(); + + public IdServiceImpl(IdProperties idProperties) { + this.index = 0; + this.serverIndex = idProperties.getServerIndex(); + this.maxIndex = idProperties.getMaxIndex(); + this.clientIndex = idProperties.getMinClientIndex(); this.minClientIndex = idProperties.getMinClientIndex(); this.maxClientIndex = idProperties.getMaxClientIndex(); } - /** - * 当前索引 - */ - private int index; - /** - * 机器序号 - */ - private final int serverIndex; - /** - * 最大序号 - */ - private final int maxIndex; - /** - * 当前终端索引 - */ - private int clientIndex; - /** - * 最小终端序号 - */ - private final int minClientIndex; - /** - * 最大终端序号 - */ - private final int maxClientIndex; - + /** + * 当前索引 + */ + private int index; + /** + * 机器序号 + */ + private final int serverIndex; + /** + * 最大序号 + */ + private final int maxIndex; + /** + * 当前终端索引 + */ + private int clientIndex; + /** + * 最小终端序号 + */ + private final int minClientIndex; + /** + * 最大终端序号 + */ + private final int maxClientIndex; + @Override - public long buildId() { + public long buildId() { int index; - synchronized (this) { - if (++this.index > this.maxIndex) { - this.index = 0; - } - index = this.index; - } - final LocalDateTime time = LocalDateTime.now(); - return - 100000000000000L * time.getDayOfMonth() + - 1000000000000L * time.getHour() + - 10000000000L * time.getMinute() + - 100000000L * time.getSecond() + - 1000000L * this.serverIndex + - index; - } + synchronized (this) { + if (++this.index > this.maxIndex) { + this.index = 0; + } + index = this.index; + } + final LocalDateTime time = LocalDateTime.now(); + return + 100000000000000L * time.getDayOfMonth() + + 1000000000000L * time.getHour() + + 10000000000L * time.getMinute() + + 100000000L * time.getSecond() + + 1000000L * this.serverIndex + + index; + } @Override public long buildClientIndex() { diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/utils/HTTPUtils.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/utils/HTTPUtils.java index 001730e..89075e4 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/utils/HTTPUtils.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/utils/HTTPUtils.java @@ -48,7 +48,7 @@ public final class HTTPUtils { * @param executor 线程池 */ public static final void init(long timeout, Executor executor) { - HTTPUtils.timeout = timeout; + HTTPUtils.timeout = timeout; HTTPUtils.executor = executor; } diff --git a/taoyao-signal-server/taoyao-server/src/main/resources/application-win.yml b/taoyao-signal-server/taoyao-server/src/main/resources/application-win.yml new file mode 100644 index 0000000..dd14500 --- /dev/null +++ b/taoyao-signal-server/taoyao-server/src/main/resources/application-win.yml @@ -0,0 +1,6 @@ +taoyao: + script: + system-reboot: shutdown /r /t 0 + system-shutdown: shutdown /s /t 0 + platform-reboot: net stop taoyao-signal-server && net start taoyao-signal-server + platform-shutdown: net stop taoyao-signal-server \ No newline at end of file diff --git a/taoyao-signal-server/taoyao-server/src/main/resources/application.yml b/taoyao-signal-server/taoyao-server/src/main/resources/application.yml index 9a74739..c854d9c 100644 --- a/taoyao-signal-server/taoyao-server/src/main/resources/application.yml +++ b/taoyao-signal-server/taoyao-server/src/main/resources/application.yml @@ -214,7 +214,7 @@ taoyao: platform-shutdown: systemctl stop taoyao-signal-server # WebRTC配置 webrtc: - # 是否加密:E2E + # 是否终端加密:E2E encrypt: false # STUN服务 stun: diff --git a/taoyao-signal-server/taoyao-signal/src/main/java/com/acgist/taoyao/signal/client/socket/SocketSignal.java b/taoyao-signal-server/taoyao-signal/src/main/java/com/acgist/taoyao/signal/client/socket/SocketSignal.java index 662466e..88ce5f9 100644 --- a/taoyao-signal-server/taoyao-signal/src/main/java/com/acgist/taoyao/signal/client/socket/SocketSignal.java +++ b/taoyao-signal-server/taoyao-signal/src/main/java/com/acgist/taoyao/signal/client/socket/SocketSignal.java @@ -119,7 +119,9 @@ public class SocketSignal { public void destroy() { log.debug("关闭Socket信令服务:{}", this.channel); CloseableUtils.close(this.channel); - this.group.shutdown(); + if(this.group != null) { + this.group.shutdown(); + } } }