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