[*] 日常优化
This commit is contained in:
@@ -8,35 +8,35 @@ package com.acgist.taoyao.media.config;
|
||||
public class Config {
|
||||
|
||||
/**
|
||||
* 屏幕捕获
|
||||
* 屏幕捕获消息
|
||||
*/
|
||||
public static final int WHAT_SCREEN_CAPTURE = 1000;
|
||||
/**
|
||||
* 视频录像
|
||||
* 视频录像消息
|
||||
*/
|
||||
public static final int WHAT_RECORD = 1001;
|
||||
/**
|
||||
* 新建本地音频
|
||||
* 新建本地音频消息
|
||||
*/
|
||||
public static final int WHAT_NEW_LOCAL_AUDIO = 2000;
|
||||
/**
|
||||
* 新建本地视频
|
||||
* 新建本地视频消息
|
||||
*/
|
||||
public static final int WHAT_NEW_LOCAL_VIDEO = 2001;
|
||||
/**
|
||||
* 新建远程音频
|
||||
* 新建远程音频消息
|
||||
*/
|
||||
public static final int WHAT_NEW_REMOTE_AUDIO = 2002;
|
||||
/**
|
||||
* 新建远程视频
|
||||
* 新建远程视频消息
|
||||
*/
|
||||
public static final int WHAT_NEW_REMOTE_VIDEO = 2003;
|
||||
/**
|
||||
* 移除远程音频
|
||||
* 移除远程音频消息
|
||||
*/
|
||||
public static final int WHAT_REMOVE_AUDIO = 2998;
|
||||
/**
|
||||
* 移除远程视频
|
||||
* 移除远程视频消息
|
||||
*/
|
||||
public static final int WHAT_REMOVE_VIDEO = 2999;
|
||||
/**
|
||||
|
||||
@@ -3,70 +3,75 @@ package com.acgist.taoyao.media.config;
|
||||
/**
|
||||
* 音频配置
|
||||
*
|
||||
* 注意:完全拷贝信令模块`MediaAudioProperties`代码
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public class MediaAudioProperties {
|
||||
|
||||
/**
|
||||
* 音频格式
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public enum Format {
|
||||
/**
|
||||
* 音频格式
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public enum Format {
|
||||
|
||||
G722,
|
||||
PCMA,
|
||||
PCMU,
|
||||
OPUS;
|
||||
G722,
|
||||
// G711A
|
||||
PCMA,
|
||||
// G711U
|
||||
PCMU,
|
||||
OPUS;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式:G722|PCMA|PCMU|OPUS
|
||||
*/
|
||||
private Format format;
|
||||
/**
|
||||
* 比特率:96|128|256
|
||||
*/
|
||||
private Integer bitrate;
|
||||
/**
|
||||
* 采样位数:8|16|32
|
||||
*/
|
||||
private Integer sampleSize;
|
||||
/**
|
||||
* 采样率:8000|16000|32000|48000
|
||||
*/
|
||||
private Integer sampleRate;
|
||||
/**
|
||||
* 格式:G722|PCMA|PCMU|OPUS
|
||||
*/
|
||||
private Format format;
|
||||
/**
|
||||
* 比特率:96|128|256
|
||||
*/
|
||||
private Integer bitrate;
|
||||
/**
|
||||
* 采样位数(位深):8|16|32
|
||||
*/
|
||||
private Integer sampleSize;
|
||||
/**
|
||||
* 采样率:8000|16000|32000|48000
|
||||
*/
|
||||
private Integer sampleRate;
|
||||
|
||||
public Format getFormat() {
|
||||
return this.format;
|
||||
}
|
||||
public Format getFormat() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public void setFormat(Format format) {
|
||||
this.format = format;
|
||||
}
|
||||
public void setFormat(Format format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public Integer getBitrate() {
|
||||
return bitrate;
|
||||
}
|
||||
public Integer getBitrate() {
|
||||
return bitrate;
|
||||
}
|
||||
|
||||
public void setBitrate(Integer bitrate) {
|
||||
this.bitrate = bitrate;
|
||||
}
|
||||
public void setBitrate(Integer bitrate) {
|
||||
this.bitrate = bitrate;
|
||||
}
|
||||
|
||||
public Integer getSampleSize() {
|
||||
return this.sampleSize;
|
||||
}
|
||||
public Integer getSampleSize() {
|
||||
return this.sampleSize;
|
||||
}
|
||||
|
||||
public void setSampleSize(Integer sampleSize) {
|
||||
this.sampleSize = sampleSize;
|
||||
}
|
||||
public void setSampleSize(Integer sampleSize) {
|
||||
this.sampleSize = sampleSize;
|
||||
}
|
||||
|
||||
public Integer getSampleRate() {
|
||||
return this.sampleRate;
|
||||
}
|
||||
public Integer getSampleRate() {
|
||||
return this.sampleRate;
|
||||
}
|
||||
|
||||
public void setSampleRate(Integer sampleRate) {
|
||||
this.sampleRate = sampleRate;
|
||||
}
|
||||
|
||||
public void setSampleRate(Integer sampleRate) {
|
||||
this.sampleRate = sampleRate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.util.Map;
|
||||
/**
|
||||
* 媒体配置
|
||||
*
|
||||
* 注意:完全拷贝信令模块`MediaProperties`代码
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public class MediaProperties {
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.acgist.taoyao.media.config;
|
||||
/**
|
||||
* 视频配置
|
||||
*
|
||||
* 注意:完全拷贝信令模块`MediaVideoProperties`代码
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public class MediaVideoProperties {
|
||||
@@ -96,4 +98,5 @@ public class MediaVideoProperties {
|
||||
public void setHeight(Integer height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class MediaAudioProperties {
|
||||
private Format format;
|
||||
@Schema(title = "比特率", description = "比特率", example = "96|128|256")
|
||||
private Integer bitrate;
|
||||
@Schema(title = "采样位数", description = "采样位数", example = "8|16|32")
|
||||
@Schema(title = "采样位数(位深)", description = "采样位数(位深)", example = "8|16|32")
|
||||
private Integer sampleSize;
|
||||
@Schema(title = "采样率", description = "采样率", example = "8000|16000|32000|48000")
|
||||
private Integer sampleRate;
|
||||
|
||||
@@ -19,14 +19,14 @@ import lombok.Setter;
|
||||
public class SecurityProperties {
|
||||
|
||||
@Schema(title = "是否启用", description = "是否启用")
|
||||
private Boolean enabled;
|
||||
private Boolean enabled;
|
||||
@Schema(title = "安全范围", description = "安全范围")
|
||||
private String realm;
|
||||
private String realm;
|
||||
@Schema(title = "公共地址", description = "公共地址")
|
||||
private String[] permit;
|
||||
@Schema(title = "名称", description = "名称")
|
||||
private String username;
|
||||
private String[] permit;
|
||||
@Schema(title = "帐号", description = "帐号")
|
||||
private String username;
|
||||
@Schema(title = "密码", description = "密码")
|
||||
private String password;
|
||||
private String password;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.acgist.taoyao.boot.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -15,6 +15,7 @@ import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.boot.model.MessageCode;
|
||||
import com.acgist.taoyao.boot.model.MessageCodeException;
|
||||
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
@@ -78,7 +79,7 @@ public final class ErrorUtils {
|
||||
* @return 错误消息
|
||||
*/
|
||||
public static final Message message(HttpServletRequest request, HttpServletResponse response) {
|
||||
return message(null, request, response);
|
||||
return ErrorUtils.message(null, request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,11 +92,11 @@ public final class ErrorUtils {
|
||||
public static final Message message(Throwable t, HttpServletRequest request, HttpServletResponse response) {
|
||||
final Message message;
|
||||
// 错误状态编码
|
||||
int status = globalStatus(request, response);
|
||||
int status = ErrorUtils.globalStatus(request, response);
|
||||
// 全局异常
|
||||
final Object globalError = t == null ? globalError(request) : t;
|
||||
final Object globalError = t == null ? ErrorUtils.globalError(request) : t;
|
||||
// 原始异常
|
||||
final Object rootError = rootException(globalError);
|
||||
final Object rootError = ErrorUtils.rootException(globalError);
|
||||
if(rootError instanceof MessageCodeException messageCodeException) {
|
||||
// 状态编码异常
|
||||
final MessageCode messageCode = messageCodeException.getMessageCode();
|
||||
@@ -103,9 +104,9 @@ public final class ErrorUtils {
|
||||
message = Message.fail(messageCode, messageCodeException.getMessage());
|
||||
} else if(rootError instanceof Throwable throwable) {
|
||||
// 未知异常:异常转换
|
||||
final MessageCode messageCode = messageCode(status, throwable);
|
||||
final MessageCode messageCode = ErrorUtils.messageCode(status, throwable);
|
||||
status = messageCode.getStatus();
|
||||
message = Message.fail(messageCode, message(messageCode, throwable));
|
||||
message = Message.fail(messageCode, ErrorUtils.message(messageCode, throwable));
|
||||
} else {
|
||||
// 没有异常
|
||||
final MessageCode messageCode = MessageCode.of(status);
|
||||
@@ -116,9 +117,19 @@ public final class ErrorUtils {
|
||||
status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
response.setStatus(status);
|
||||
// 打印信息
|
||||
final String path = Objects.toString(request.getAttribute(SERVLET_REQUEST_URI), request.getServletPath());
|
||||
final String query = request.getQueryString();
|
||||
// 请求地址
|
||||
final String path = ErrorUtils.getFirstParams(
|
||||
request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI),
|
||||
request.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH),
|
||||
request.getAttribute(SERVLET_REQUEST_URI),
|
||||
request.getServletPath()
|
||||
);
|
||||
// 请求参数
|
||||
final String query = ErrorUtils.getFirstParams(
|
||||
request.getAttribute(RequestDispatcher.FORWARD_QUERY_STRING),
|
||||
request.getQueryString()
|
||||
);
|
||||
// 请求方法
|
||||
final String method = request.getMethod();
|
||||
if(globalError instanceof Throwable) {
|
||||
log.error("""
|
||||
@@ -140,11 +151,11 @@ public final class ErrorUtils {
|
||||
原始信息:{}
|
||||
""", path, query, method, message, status, globalError);
|
||||
}
|
||||
// final Map<String, String> body = new HashMap<>();
|
||||
// body.put("url", path);
|
||||
// body.put("query", query);
|
||||
// body.put("method", method);
|
||||
// message.setBody(body);
|
||||
final Map<String, String> body = new HashMap<>();
|
||||
body.put("path", path);
|
||||
body.put("query", query);
|
||||
body.put("method", method);
|
||||
message.setBody(body);
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -241,7 +252,7 @@ public final class ErrorUtils {
|
||||
*/
|
||||
public static final Object rootException(Object t) {
|
||||
if(t instanceof Throwable throwable) {
|
||||
return rootException(throwable);
|
||||
return ErrorUtils.rootException(throwable);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
@@ -263,4 +274,18 @@ public final class ErrorUtils {
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param params 参数列表
|
||||
*
|
||||
* @return 首个参数
|
||||
*/
|
||||
private static final String getFirstParams(Object ... params) {
|
||||
for (Object object : params) {
|
||||
if(object != null) {
|
||||
return object.toString();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ public class TaoyaoAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "taoyao.security", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnMissingBean
|
||||
public SecurityInterceptor securityInterceptor(SecurityService securityService, SecurityProperties securityProperties) {
|
||||
public SecurityInterceptor securityInterceptor(
|
||||
SecurityService securityService,
|
||||
SecurityProperties securityProperties
|
||||
) {
|
||||
return new SecurityInterceptor(securityService, securityProperties);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,16 +27,22 @@ public class SecurityInterceptor extends InterceptorAdapter {
|
||||
private final SecurityService securityService;
|
||||
private final SecurityProperties securityProperties;
|
||||
|
||||
public SecurityInterceptor(SecurityService securityService, SecurityProperties securityProperties) {
|
||||
this.securityService = securityService;
|
||||
this.securityProperties = securityProperties;
|
||||
log.info("安全拦截密码:{}", securityProperties.getPassword());
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 鉴权信息
|
||||
*/
|
||||
private final String authenticate;
|
||||
/**
|
||||
* 地址匹配
|
||||
*/
|
||||
private final AntPathMatcher matcher = new AntPathMatcher();
|
||||
private final AntPathMatcher matcher;
|
||||
|
||||
public SecurityInterceptor(SecurityService securityService, SecurityProperties securityProperties) {
|
||||
this.securityService = securityService;
|
||||
this.securityProperties = securityProperties;
|
||||
this.authenticate = "Basic Realm=\"" + this.securityProperties.getRealm() + "\"";
|
||||
this.matcher = new AntPathMatcher();
|
||||
log.info("安全拦截密码:{}", securityProperties.getPassword());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
@@ -62,7 +68,7 @@ public class SecurityInterceptor extends InterceptorAdapter {
|
||||
log.debug("授权失败:{}", request.getRequestURL());
|
||||
}
|
||||
response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
||||
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic Realm=\"" + this.securityProperties.getRealm() + "\"");
|
||||
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, this.authenticate);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -72,7 +78,7 @@ public class SecurityInterceptor extends InterceptorAdapter {
|
||||
* @return 是否许可请求
|
||||
*/
|
||||
private boolean permit(HttpServletRequest request) {
|
||||
final String uri = request.getRequestURI();
|
||||
final String uri = request.getRequestURI();
|
||||
final String[] permit = this.securityProperties.getPermit();
|
||||
if(ArrayUtils.isEmpty(permit)) {
|
||||
return false;
|
||||
|
||||
@@ -17,14 +17,15 @@ public class SlowInterceptor extends InterceptorAdapter {
|
||||
|
||||
private final TaoyaoProperties taoyaoProperties;
|
||||
|
||||
public SlowInterceptor(TaoyaoProperties taoyaoProperties) {
|
||||
this.taoyaoProperties = taoyaoProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 请求开始时间
|
||||
*/
|
||||
private final ThreadLocal<Long> local = new ThreadLocal<>();
|
||||
private final ThreadLocal<Long> local;
|
||||
|
||||
public SlowInterceptor(TaoyaoProperties taoyaoProperties) {
|
||||
this.taoyaoProperties = taoyaoProperties;
|
||||
this.local = new ThreadLocal<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
@@ -52,7 +53,7 @@ public class SlowInterceptor extends InterceptorAdapter {
|
||||
final long duration;
|
||||
final Long last = this.local.get();
|
||||
if(last != null && (duration = System.currentTimeMillis() - last) > this.taoyaoProperties.getTimeout()) {
|
||||
log.info("请求执行时间过慢:{}-{}", request.getRequestURI(), duration);
|
||||
log.info("请求执行时间过慢:{} - {}", request.getRequestURI(), duration);
|
||||
}
|
||||
this.local.remove();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.acgist.taoyao.signal.service;
|
||||
|
||||
/**
|
||||
* 用户密码认证服务
|
||||
* 帐号密码认证服务
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@@ -10,8 +10,8 @@ public interface UsernamePasswordService {
|
||||
/**
|
||||
* 认证
|
||||
*
|
||||
* @param username 用户名称
|
||||
* @param password 用户密码
|
||||
* @param username 帐号
|
||||
* @param password 密码
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user