[+] 证书终端请求ID
This commit is contained in:
@@ -27,7 +27,7 @@ public @interface Description {
|
||||
/**
|
||||
* @return 数据流向
|
||||
*/
|
||||
String[] flow() default { "终端->信令服务->终端" };
|
||||
String[] flow() default { "终端=>信令服务->终端" };
|
||||
|
||||
/**
|
||||
* @return 描述信息
|
||||
|
||||
@@ -1,234 +1,238 @@
|
||||
package com.acgist.taoyao.boot.config;
|
||||
|
||||
/**
|
||||
* 字符常量
|
||||
* 常量
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public interface Constant {
|
||||
|
||||
/**
|
||||
* 接收方的终端标识
|
||||
*/
|
||||
String TO = "to";
|
||||
/**
|
||||
* 换行
|
||||
*/
|
||||
String LINE = "\n";
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
String IP = "ip";
|
||||
/**
|
||||
* 接收方
|
||||
*/
|
||||
String TO = "to";
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
String STATUS = "status";
|
||||
/**
|
||||
* 配置
|
||||
*/
|
||||
String CONFIG = "config";
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
String LATITUDE = "latitude";
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
String LONGITUDE = "longitude";
|
||||
/**
|
||||
* 湿度
|
||||
*/
|
||||
String HUMIDITY = "humidity";
|
||||
/**
|
||||
* 温度
|
||||
*/
|
||||
String TEMPERATURE = "temperature";
|
||||
/**
|
||||
* 信号强度(0~100)
|
||||
*/
|
||||
String SIGNAL = "signal";
|
||||
/**
|
||||
* 电池电量(0~100)
|
||||
*/
|
||||
String BATTERY = "battery";
|
||||
/**
|
||||
* 是否正在运行
|
||||
*/
|
||||
String RUNNING = "running";
|
||||
/**
|
||||
* 是否正在充电
|
||||
*/
|
||||
String CHARGING = "charging";
|
||||
/**
|
||||
* 是否正在录像
|
||||
*/
|
||||
String RECORDING = "recording";
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
String URLS = "urls";
|
||||
/**
|
||||
* 凭证
|
||||
*/
|
||||
String CREDENTIAL = "credential";
|
||||
/**
|
||||
* 最小
|
||||
*/
|
||||
String MIN = "min";
|
||||
/**
|
||||
* 最大
|
||||
*/
|
||||
String MAX = "max";
|
||||
/**
|
||||
* 建议
|
||||
*/
|
||||
String IDEAL = "ideal";
|
||||
/**
|
||||
* 最小宽度
|
||||
*/
|
||||
Integer MIN_WIDTH = 720;
|
||||
/**
|
||||
* 最大宽度
|
||||
*/
|
||||
Integer MAX_WIDTH = 4096;
|
||||
/**
|
||||
* 最小高度
|
||||
*/
|
||||
Integer MIN_HEIGHT = 480;
|
||||
/**
|
||||
* 最大高度
|
||||
*/
|
||||
Integer MAX_HEIGHT = 2160;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
String NAME = "name";
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
String CLIENT_TYPE = "clientType";
|
||||
/**
|
||||
* 脚本
|
||||
*/
|
||||
String SCRIPT = "script";
|
||||
/**
|
||||
* 结果
|
||||
*/
|
||||
String RESULT = "result";
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
String MESSAGE = "message";
|
||||
/**
|
||||
* 请求
|
||||
*/
|
||||
String REQUEST = "request";
|
||||
/**
|
||||
* 帐号
|
||||
*/
|
||||
String USERNAME = "username";
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
String PASSWORD = "password";
|
||||
/**
|
||||
* 媒体类型
|
||||
*/
|
||||
String KIND = "kind";
|
||||
/**
|
||||
* 媒体
|
||||
*/
|
||||
String MEDIA = "media";
|
||||
/**
|
||||
* WebRTC
|
||||
*/
|
||||
String WEBRTC = "webrtc";
|
||||
/**
|
||||
* 日期时间
|
||||
*/
|
||||
String DATETIME = "datetime";
|
||||
/**
|
||||
* 房间ID
|
||||
*/
|
||||
String ROOM_ID = "roomId";
|
||||
/**
|
||||
* 媒体服务ID
|
||||
*/
|
||||
String MEDIA_ID = "mediaId";
|
||||
/**
|
||||
* 媒体流ID
|
||||
*/
|
||||
String STREAM_ID = "streamId";
|
||||
/**
|
||||
* 终端ID
|
||||
*/
|
||||
String CLIENT_ID = "clientId";
|
||||
/**
|
||||
* 来源终端ID
|
||||
*/
|
||||
String SOURCE_ID = "sourceId";
|
||||
/**
|
||||
* 路由ID
|
||||
*/
|
||||
String ROUTER_ID = "routerId";
|
||||
/**
|
||||
* 传输通道ID
|
||||
*/
|
||||
String TRANSPORT_ID = "transportId";
|
||||
/**
|
||||
* 生产者ID
|
||||
*/
|
||||
String PRODUCER_ID = "producerId";
|
||||
/**
|
||||
* 消费者ID
|
||||
*/
|
||||
String CONSUMER_ID = "consumerId";
|
||||
/**
|
||||
* 数据生产者ID
|
||||
*/
|
||||
String DATA_PRODUCER_ID = "dataProducerId";
|
||||
/**
|
||||
* 数据消费者ID
|
||||
*/
|
||||
String DATA_CONSUMER_ID = "dataConsumerId";
|
||||
/**
|
||||
* ICE服务:P2P直连使用
|
||||
*/
|
||||
String ICE_SERVERS = "iceServers";
|
||||
/**
|
||||
* ICE候选
|
||||
*/
|
||||
String ICE_CANDIDATES = "iceCandidates";
|
||||
/**
|
||||
* ICE参数
|
||||
*/
|
||||
String ICE_PARAMETERS = "iceParameters";
|
||||
/**
|
||||
* DTLS参数
|
||||
*/
|
||||
String DTLS_PARAMETERS = "dtlsParameters";
|
||||
/**
|
||||
* SCTP参数
|
||||
*/
|
||||
String SCTP_PARAMETERS = "sctpParameters";
|
||||
/**
|
||||
* RTP能力
|
||||
*/
|
||||
String RTP_CAPABILITIES = "rtpCapabilities";
|
||||
/**
|
||||
* SCTP能力
|
||||
*/
|
||||
String SCTP_CAPABILITIES = "sctpCapabilities";
|
||||
/**
|
||||
* 生产者
|
||||
*/
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
String IP = "ip";
|
||||
/**
|
||||
* 状态对象
|
||||
*/
|
||||
String STATUS = "status";
|
||||
/**
|
||||
* 配置对象
|
||||
*/
|
||||
String CONFIG = "config";
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
String LATITUDE = "latitude";
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
String LONGITUDE = "longitude";
|
||||
/**
|
||||
* 湿度
|
||||
*/
|
||||
String HUMIDITY = "humidity";
|
||||
/**
|
||||
* 温度
|
||||
*/
|
||||
String TEMPERATURE = "temperature";
|
||||
/**
|
||||
* 信号强度(0~100)
|
||||
*/
|
||||
String SIGNAL = "signal";
|
||||
/**
|
||||
* 电池电量(0~100)
|
||||
*/
|
||||
String BATTERY = "battery";
|
||||
/**
|
||||
* 是否正在充电
|
||||
*/
|
||||
String CHARGING = "charging";
|
||||
/**
|
||||
* 是否正在录像
|
||||
*/
|
||||
String RECORDING = "recording";
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
String URLS = "urls";
|
||||
/**
|
||||
* 凭证
|
||||
*/
|
||||
String CREDENTIAL = "credential";
|
||||
/**
|
||||
* 最小
|
||||
*/
|
||||
String MIN = "min";
|
||||
/**
|
||||
* 最大
|
||||
*/
|
||||
String MAX = "max";
|
||||
/**
|
||||
* 建议
|
||||
*/
|
||||
String IDEAL = "ideal";
|
||||
/**
|
||||
* 最小宽度
|
||||
*/
|
||||
Integer MIN_WIDTH = 720;
|
||||
/**
|
||||
* 最大宽度
|
||||
*/
|
||||
Integer MAX_WIDTH = 4096;
|
||||
/**
|
||||
* 最小高度
|
||||
*/
|
||||
Integer MIN_HEIGHT = 480;
|
||||
/**
|
||||
* 最大高度
|
||||
*/
|
||||
Integer MAX_HEIGHT = 2160;
|
||||
/**
|
||||
* 脚本
|
||||
*/
|
||||
String SCRIPT = "script";
|
||||
/**
|
||||
* 结果
|
||||
*/
|
||||
String RESULT = "result";
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
String MESSAGE = "message";
|
||||
/**
|
||||
* 请求
|
||||
*/
|
||||
String REQUEST = "request";
|
||||
/**
|
||||
* 响应
|
||||
*/
|
||||
String RESPONSE = "response";
|
||||
/**
|
||||
* 帐号
|
||||
*/
|
||||
String USERNAME = "username";
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
String PASSWORD = "password";
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
String NAME = "name";
|
||||
/**
|
||||
* 媒体类型
|
||||
*/
|
||||
String KIND = "kind";
|
||||
/**
|
||||
* 索引
|
||||
*/
|
||||
String INDEX = "index";
|
||||
/**
|
||||
* 媒体
|
||||
*/
|
||||
String MEDIA = "media";
|
||||
/**
|
||||
* WebRTC
|
||||
*/
|
||||
String WEBRTC = "webrtc";
|
||||
/**
|
||||
* 日期时间
|
||||
*/
|
||||
String DATETIME = "datetime";
|
||||
/**
|
||||
* 终端类型
|
||||
*/
|
||||
String CLIENT_TYPE = "clientType";
|
||||
/**
|
||||
* 房间ID
|
||||
*/
|
||||
String ROOM_ID = "roomId";
|
||||
/**
|
||||
* 媒体服务ID
|
||||
*/
|
||||
String MEDIA_ID = "mediaId";
|
||||
/**
|
||||
* 媒体流ID
|
||||
*/
|
||||
String STREAM_ID = "streamId";
|
||||
/**
|
||||
* 终端ID
|
||||
*/
|
||||
String CLIENT_ID = "clientId";
|
||||
/**
|
||||
* 来源终端ID
|
||||
*/
|
||||
String SOURCE_ID = "sourceId";
|
||||
/**
|
||||
* 传输通道ID
|
||||
*/
|
||||
String TRANSPORT_ID = "transportId";
|
||||
/**
|
||||
* 生产者ID
|
||||
*/
|
||||
String PRODUCER_ID = "producerId";
|
||||
/**
|
||||
* 消费者ID
|
||||
*/
|
||||
String CONSUMER_ID = "consumerId";
|
||||
/**
|
||||
* 数据生产者ID
|
||||
*/
|
||||
String DATA_PRODUCER_ID = "dataProducerId";
|
||||
/**
|
||||
* 数据消费者ID
|
||||
*/
|
||||
String DATA_CONSUMER_ID = "dataConsumerId";
|
||||
/**
|
||||
* ICE服务
|
||||
*/
|
||||
String ICE_SERVERS = "iceServers";
|
||||
/**
|
||||
* ICE候选
|
||||
*/
|
||||
String ICE_CANDIDATES = "iceCandidates";
|
||||
/**
|
||||
* ICE参数
|
||||
*/
|
||||
String ICE_PARAMETERS = "iceParameters";
|
||||
/**
|
||||
* RTP参数
|
||||
*/
|
||||
String RTP_PARAMETERS = "rtpParameters";
|
||||
/**
|
||||
* RTP能力
|
||||
*/
|
||||
String RTP_CAPABILITIES = "rtpCapabilities";
|
||||
/**
|
||||
* DTLS参数
|
||||
*/
|
||||
String DTLS_PARAMETERS = "dtlsParameters";
|
||||
/**
|
||||
* SCTP参数
|
||||
*/
|
||||
String SCTP_PARAMETERS = "sctpParameters";
|
||||
/**
|
||||
* SCTP能力
|
||||
*/
|
||||
String SCTP_CAPABILITIES = "sctpCapabilities";
|
||||
/**
|
||||
* 是否是消费者
|
||||
*/
|
||||
String CONSUMING = "consuming";
|
||||
/**
|
||||
* 消费者
|
||||
* 是否是生产者
|
||||
*/
|
||||
String PRODUCING = "producing";
|
||||
/**
|
||||
* 订阅类型
|
||||
* 媒体订阅类型
|
||||
*/
|
||||
String SUBSCRIBE_TYPE = "subscribeType";
|
||||
|
||||
|
||||
@@ -9,6 +9,14 @@ import lombok.Setter;
|
||||
/**
|
||||
* ID配置
|
||||
*
|
||||
* 服务端:日期 + 两位机器序号 + 六位索引
|
||||
* 范围:00000000~09999999
|
||||
* 并发:1000000 / S
|
||||
*
|
||||
* 终端:日期 + 五位机器序号 + 三位索引
|
||||
* 范围:10000000~99999999
|
||||
* 并发:1000 / S
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Getter
|
||||
@@ -17,9 +25,13 @@ import lombok.Setter;
|
||||
@ConfigurationProperties(prefix = "taoyao.id")
|
||||
public class IdProperties {
|
||||
|
||||
@Schema(title = "机器序号", description = "机器序号")
|
||||
private Integer index;
|
||||
@Schema(title = "最大序号", description = "最大序号")
|
||||
private Integer maxIndex;
|
||||
@Schema(title = "机器序号", description = "机器序号")
|
||||
private Integer serverIndex;
|
||||
@Schema(title = "最小终端序号", description = "最小终端序号")
|
||||
private Integer minClientIndex;
|
||||
@Schema(title = "最大终端序号", description = "最大终端序号")
|
||||
private Integer maxClientIndex;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import lombok.Setter;
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema( title = "消息头部", description = "消息头部")
|
||||
@Schema(title = "消息头部", description = "消息头部")
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.acgist.taoyao.boot.utils.JSONUtils;
|
||||
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -26,6 +27,7 @@ import lombok.Setter;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonIncludeProperties(value = { "code", "message", "header", "body" })
|
||||
public class Message implements Cloneable, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -183,7 +185,7 @@ public class Message implements Cloneable, Serializable {
|
||||
* @return Map消息主体
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Map<String, Object> mapBody() {
|
||||
public Map<String, Object> body() {
|
||||
if(this.body instanceof Map map) {
|
||||
return map;
|
||||
} else if(this.body == null) {
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
package com.acgist.taoyao.boot.service;
|
||||
|
||||
/**
|
||||
* ID生成器
|
||||
* 只能用于生成消息标识
|
||||
* 生成ID服务
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public interface IdService {
|
||||
|
||||
/**
|
||||
* 生成十六位的ID:ddHHmmss(8) + index(2) + xxxxxx(6)
|
||||
* 生成十六位的消息ID:ddHHmmss(8) + index(2) + xxxxxx(6)
|
||||
* 只能用于生成消息ID:JS超过`Number.MAX_SAFE_INTEGER`丢失精度
|
||||
*
|
||||
* @return ID
|
||||
*/
|
||||
long buildId();
|
||||
|
||||
/**
|
||||
* 生成唯一ID
|
||||
* @return 终端索引
|
||||
*/
|
||||
long buildClientIndex();
|
||||
|
||||
/**
|
||||
* 生成三十二位唯一ID
|
||||
*
|
||||
* @return ID
|
||||
*/
|
||||
|
||||
@@ -8,23 +8,48 @@ import com.acgist.taoyao.boot.service.IdService;
|
||||
|
||||
public class IdServiceImpl implements IdService {
|
||||
|
||||
private final IdProperties idProperties;
|
||||
|
||||
public IdServiceImpl(IdProperties idProperties) {
|
||||
this.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;
|
||||
|
||||
@Override
|
||||
public long buildId() {
|
||||
int index;
|
||||
synchronized (this) {
|
||||
if (++this.index > this.idProperties.getMaxIndex()) {
|
||||
if (++this.index > this.maxIndex) {
|
||||
this.index = 0;
|
||||
}
|
||||
index = this.index;
|
||||
}
|
||||
final LocalDateTime time = LocalDateTime.now();
|
||||
return
|
||||
@@ -32,14 +57,25 @@ public class IdServiceImpl implements IdService {
|
||||
1000000000000L * time.getHour() +
|
||||
10000000000L * time.getMinute() +
|
||||
100000000L * time.getSecond() +
|
||||
1000000L * this.idProperties.getIndex() +
|
||||
// 每秒并发数量
|
||||
this.index;
|
||||
1000000L * this.serverIndex +
|
||||
index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long buildClientIndex() {
|
||||
int index;
|
||||
synchronized (this) {
|
||||
if(++this.clientIndex > this.maxClientIndex) {
|
||||
this.clientIndex = this.minClientIndex;
|
||||
}
|
||||
index = this.clientIndex;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildUuid() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user