[*] 日常优化
This commit is contained in:
@@ -18,7 +18,7 @@ import lombok.Setter;
|
||||
public class SocketProperties {
|
||||
|
||||
/**
|
||||
* 机密策略
|
||||
* 加密策略
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
|
||||
@@ -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,7 +21,7 @@ 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;
|
||||
@@ -34,18 +33,16 @@ public class WebrtcProperties {
|
||||
final List<Map<String, String>> list = new ArrayList<>();
|
||||
if(this.stun != null) {
|
||||
for (WebrtcStunProperties stun : this.stun) {
|
||||
final Map<String, String> 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<String, String> 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;
|
||||
|
||||
@@ -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 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) {
|
||||
@@ -165,7 +160,6 @@ 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 String totalMemory = FileUtils.formatSize(runtime.totalMemory());
|
||||
@@ -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);
|
||||
|
||||
@@ -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,10 +39,6 @@ public class SpringDocAutoConfiguration {
|
||||
|
||||
private final TaoyaoProperties taoyaoProperties;
|
||||
|
||||
public SpringDocAutoConfiguration(TaoyaoProperties taoyaoProperties) {
|
||||
this.taoyaoProperties = taoyaoProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi signalApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
|
||||
@@ -7,25 +7,21 @@ 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()
|
||||
@@ -39,9 +35,4 @@ public class WebMvcConfigurerAutoConfiguration implements WebMvcConfigurer {
|
||||
});
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void addCorsMappings(CorsRegistry registry) {
|
||||
// WebMvcConfigurer.super.addCorsMappings(registry);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
/**
|
||||
* 统一异常处理
|
||||
*
|
||||
* 不能处理:https://localhost:8888/?\%3E%3C
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Tag(name = "统一异常处理", description = "全局统一异常处理")
|
||||
|
||||
@@ -54,7 +54,7 @@ public class Message implements Cloneable, Serializable {
|
||||
private Object body;
|
||||
|
||||
public Message() {
|
||||
// 默认消息都是成功
|
||||
// 消息默认都是成功
|
||||
final MessageCode messageCode = MessageCode.CODE_0000;
|
||||
this.code = messageCode.getCode();
|
||||
this.message = messageCode.getMessage();
|
||||
@@ -205,13 +205,6 @@ 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);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.acgist.taoyao.boot.model;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 可修改的Optional
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public final class ModifyOptional<T> {
|
||||
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
private T t;
|
||||
/**
|
||||
* 生产者
|
||||
*/
|
||||
private Supplier<T> supplier;
|
||||
|
||||
private ModifyOptional(T t, Supplier<T> supplier) {
|
||||
this.t = t;
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
public static final <T> ModifyOptional<T> of(T t) {
|
||||
return new ModifyOptional<>(t, null);
|
||||
}
|
||||
|
||||
public static final <T> ModifyOptional<T> of(Supplier<T> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -214,7 +214,7 @@ taoyao:
|
||||
platform-shutdown: systemctl stop taoyao-signal-server
|
||||
# WebRTC配置
|
||||
webrtc:
|
||||
# 是否加密:E2E
|
||||
# 是否终端加密:E2E
|
||||
encrypt: false
|
||||
# STUN服务
|
||||
stun:
|
||||
|
||||
@@ -119,7 +119,9 @@ public class SocketSignal {
|
||||
public void destroy() {
|
||||
log.debug("关闭Socket信令服务:{}", this.channel);
|
||||
CloseableUtils.close(this.channel);
|
||||
if(this.group != null) {
|
||||
this.group.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user