[+] media::transport::webrtc::connect

This commit is contained in:
acgist
2023-02-19 11:57:09 +08:00
parent 9023883c5b
commit fd505dfbd2
105 changed files with 1511 additions and 2116 deletions

View File

@@ -0,0 +1,39 @@
package com.acgist.taoyao.boot.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.stereotype.Component;
/**
* 信令描述
* 生成文档采用`RUNTIME`
*
* @author acgist
*/
@Target(ElementType.TYPE)
@Component
//@Retention(RetentionPolicy.SOURCE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Description {
/**
* @return 消息主体
*/
String[] body() default { "{}" };
/**
* @return 数据流向
*/
String[] flow() default { "终端->信令服务->终端" };
/**
* @return 描述信息
*/
String memo() default "";
}

View File

@@ -18,5 +18,5 @@ import org.springframework.stereotype.Component;
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Protocol {
}

View File

@@ -35,9 +35,9 @@ public class Header implements Serializable {
@Schema(title = "消息标识", description = "消息标识")
private String id;
/**
* 协议标识
* 信令标识
*/
@Schema(title = "协议标识", description = "协议标识")
@Schema(title = "信令标识", description = "信令标识")
private String signal;
@Override

View File

@@ -186,7 +186,7 @@ public class Message implements Cloneable, Serializable {
*
* @return 克隆消息
*/
public Message cloneWidthoutBody() {
public Message cloneWithoutBody() {
final Message message = this.clone();
message.setBody(null);
return message;

View File

@@ -0,0 +1,159 @@
package com.acgist.taoyao.boot.property;
/**
* 字符常量
*
* @author acgist
*/
public interface Constant {
/**
* 换行
*/
String LINE = "\n";
/**
* IP
*/
String IP = "ip";
/**
* 接收方
*/
String TO = "to";
/**
* 发送方
*/
String FROM = "from";
/**
* 信号强度0~100
*/
String SIGNAL = "signal";
/**
* 电池电量0~100
*/
String BATTERY = "battery";
/**
* 是否正在充电
*/
String CHARGING = "charging";
/**
* 地址
*/
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 SCRIPT = "script";
/**
* 结果
*/
String RESULT = "result";
/**
* 请求
*/
String REQUEST = "request";
/**
* 帐号
*/
String USERNAME = "username";
/**
* 密码
*/
String PASSWORD = "password";
/**
* 时间
*/
String TIME = "time";
/**
* 媒体
*/
String MEDIA = "media";
/**
* WebRTC
*/
String WEBRTC = "webrtc";
/**
* PeerId
*
* @see #CLIENT_ID
*/
String PEER_ID = "peerId";
/**
* 房间ID
*/
String ROOM_ID = "roomId";
/**
* 媒体服务ID
*/
String MEDIA_ID = "mediaId";
/**
* 终端ID
*
* @see #PEER_ID
*/
String CLIENT_ID = "clientId";
/**
* 路由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";
String ICE_CANDIDATES = "iceCandidates";
String ICE_PARAMETERS = "iceParameters";
String DTLS_PARAMETERS = "dtlsParameters";
String SCTP_PARAMETERS = "sctpParameters";
}

View File

@@ -19,9 +19,9 @@ import lombok.Setter;
@ConfigurationProperties(prefix = "taoyao.media")
public class MediaProperties {
@Schema(title = "音频配置", description = "音频配置")
@Schema(title = "音频默认配置", description = "音频默认配置")
private MediaAudioProperties audio;
@Schema(title = "视频配置", description = "视频配置")
@Schema(title = "视频默认配置", description = "视频默认配置")
private MediaVideoProperties video;
@Schema(title = "4K视频配置", description = "4K视频配置")
private MediaVideoProperties udVideo;

View File

@@ -1,5 +1,8 @@
package com.acgist.taoyao.boot.property;
import java.util.LinkedHashMap;
import java.util.Map;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
@@ -36,23 +39,29 @@ public class MediaVideoProperties {
private Integer frameRate;
@Schema(title = "分辨率", description = "分辨率影响画面大小", example = "1920*1080|1280*720")
private String resolution;
@Schema(title = "宽度", description = "宽度")
private Integer width;
@Schema(title = "高度", description = "高度")
private Integer height;
@Schema(title = "宽度", description = "宽度", example = "{ min: 720, ideal: 1280, max: 4096 }")
private Map<String, Object> width;
@Schema(title = "高度", description = "高度", example = "{ min: 480, ideal: 720, max: 2160 }")
private Map<String, Object> height;
public Integer getWidth() {
public Map<String, Object> getWidth() {
if(this.width == null) {
final int index = this.resolution.indexOf('*');
this.width = Integer.valueOf(this.resolution.substring(0, index).strip());
final int index = this.resolution.indexOf('*');
this.width = new LinkedHashMap<>();
this.width.put(Constant.MIN, Constant.MIN_WIDTH);
this.width.put(Constant.IDEAL, Integer.valueOf(this.resolution.substring(0, index).strip()));
this.width.put(Constant.MAX, Constant.MAX_WIDTH);
}
return this.width;
}
public Integer getHeight() {
public Map<String, Object> getHeight() {
if(this.height == null) {
final int index = this.resolution.indexOf('*');
this.height = Integer.valueOf(this.resolution.substring(index + 1).strip());
this.height = new LinkedHashMap<>();
this.height.put(Constant.MIN, Constant.MIN_HEIGHT);
this.height.put(Constant.IDEAL, Integer.valueOf(this.resolution.substring(index + 1).strip()));
this.height.put(Constant.MAX, Constant.MAX_HEIGHT);
}
return this.height;
}

View File

@@ -1,5 +1,10 @@
package com.acgist.taoyao.boot.property;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -22,4 +27,26 @@ public class WebrtcProperties {
@Schema(title = "TURN服务器", description = "TURN服务器")
private WebrtcTurnProperties[] turn;
@Schema(title = "IceServers", description = "IceServers")
public List<Map<String, String>> getIceServers() {
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);
}
}
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);
}
}
return list;
}
}

View File

@@ -21,7 +21,7 @@ public class WebrtcStunProperties {
@Schema(title = "完整地址", description = "完整地址")
public String getAddress() {
return "stun://" + this.host + ":" + this.port;
return "stun:" + this.host + ":" + this.port;
}
}

View File

@@ -21,7 +21,7 @@ public class WebrtcTurnProperties extends WebrtcStunProperties {
@Schema(title = "完整地址", description = "完整地址")
public String getAddress() {
return "turn://" + this.host + ":" + this.port;
return "turn:" + this.host + ":" + this.port;
}
}

View File

@@ -22,7 +22,9 @@ public final class CloseableUtils {
*/
public static final void close(Closeable closeable) {
try {
closeable.close();
if(closeable != null) {
closeable.close();
}
} catch (Exception e) {
log.error("关闭资源异常", e);
}
@@ -35,7 +37,9 @@ public final class CloseableUtils {
*/
public static final void close(AutoCloseable closeable) {
try {
closeable.close();
if(closeable != null) {
closeable.close();
}
} catch (Exception e) {
log.error("关闭资源异常", e);
}