[+] 优化房间创建、关闭、广播、终端列表逻辑
现在已经能够拉出视频
This commit is contained in:
@@ -143,10 +143,6 @@ public interface Constant {
|
||||
* 房间ID
|
||||
*/
|
||||
String ROOM_ID = "roomId";
|
||||
/**
|
||||
* 媒体服务ID
|
||||
*/
|
||||
String MEDIA_ID = "mediaId";
|
||||
/**
|
||||
* 媒体流ID
|
||||
*/
|
||||
@@ -179,6 +175,10 @@ public interface Constant {
|
||||
* 数据消费者ID
|
||||
*/
|
||||
String DATA_CONSUMER_ID = "dataConsumerId";
|
||||
/**
|
||||
* 媒体服务ID
|
||||
*/
|
||||
String MEDIA_CLIENT_ID = "mediaClientId";
|
||||
/**
|
||||
* ICE服务
|
||||
*/
|
||||
|
||||
@@ -162,11 +162,11 @@ public class BootAutoConfiguration {
|
||||
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());
|
||||
final String maxMemory = FileUtils.formatSize(runtime.maxMemory());
|
||||
log.info("操作系统名称:{}", System.getProperty("os.name"));
|
||||
log.info("操作系统架构:{}", System.getProperty("os.arch"));
|
||||
log.info("操作系统名称:{}", System.getProperty("os.name"));
|
||||
log.info("操作系统版本:{}", System.getProperty("os.version"));
|
||||
log.info("可用的处理器数量:{}", runtime.availableProcessors());
|
||||
log.info("Java版本:{}", System.getProperty("java.version"));
|
||||
@@ -175,9 +175,9 @@ public class BootAutoConfiguration {
|
||||
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("虚拟机最大内存:{}", maxMemory);
|
||||
log.info("虚拟机空闲内存:{}", freeMemory);
|
||||
log.info("虚拟机已用内存:{}", totalMemory);
|
||||
log.info("虚拟机最大内存:{}", maxMemory);
|
||||
log.info("工作目录:{}", System.getProperty("user.dir"));
|
||||
log.info("用户目录:{}", System.getProperty("user.home"));
|
||||
log.info("临时目录:{}", System.getProperty("java.io.tmpdir"));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.acgist.taoyao.boot.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -61,8 +62,35 @@ public final class MapUtils {
|
||||
return null;
|
||||
} else if(object instanceof Long value) {
|
||||
return value;
|
||||
} else if(object instanceof Integer value) {
|
||||
return value.longValue();
|
||||
} else if(object instanceof Double value) {
|
||||
return value.longValue();
|
||||
}
|
||||
return Long.valueOf(object.toString());
|
||||
return new BigDecimal(object.toString()).longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param body 消息主体
|
||||
* @param key 参数名称
|
||||
*
|
||||
* @return 参数值
|
||||
*/
|
||||
public static final Double getDouble(Map<?, ?> body, String key) {
|
||||
if(body == null) {
|
||||
return null;
|
||||
}
|
||||
final Object object = body.get(key);
|
||||
if(object == null) {
|
||||
return null;
|
||||
} else if(object instanceof Long value) {
|
||||
return value.doubleValue();
|
||||
} else if(object instanceof Integer value) {
|
||||
return value.doubleValue();
|
||||
} else if(object instanceof Double value) {
|
||||
return value;
|
||||
}
|
||||
return new BigDecimal(object.toString()).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,10 +106,14 @@ public final class MapUtils {
|
||||
final Object object = body.get(key);
|
||||
if(object == null) {
|
||||
return null;
|
||||
} else if(object instanceof Long value) {
|
||||
return value.intValue();
|
||||
} else if(object instanceof Integer value) {
|
||||
return value;
|
||||
} else if(object instanceof Double value) {
|
||||
return value.intValue();
|
||||
}
|
||||
return Integer.valueOf(object.toString());
|
||||
return new BigDecimal(object.toString()).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,12 +60,12 @@ public class ClientStatus {
|
||||
* @param body 消息主体
|
||||
*/
|
||||
public void copy(Map<String, Object> body) {
|
||||
this.setLatitude(MapUtils.get(body, Constant.LATITUDE));
|
||||
this.setLongitude(MapUtils.get(body, Constant.LONGITUDE));
|
||||
this.setHumidity(MapUtils.get(body, Constant.HUMIDITY));
|
||||
this.setTemperature(MapUtils.get(body, Constant.TEMPERATURE));
|
||||
this.setSignal(MapUtils.get(body, Constant.SIGNAL));
|
||||
this.setBattery(MapUtils.get(body, Constant.BATTERY));
|
||||
this.setLatitude(MapUtils.getDouble(body, Constant.LATITUDE));
|
||||
this.setLongitude(MapUtils.getDouble(body, Constant.LONGITUDE));
|
||||
this.setHumidity(MapUtils.getDouble(body, Constant.HUMIDITY));
|
||||
this.setTemperature(MapUtils.getDouble(body, Constant.TEMPERATURE));
|
||||
this.setSignal(MapUtils.getInteger(body, Constant.SIGNAL));
|
||||
this.setBattery(MapUtils.getInteger(body, Constant.BATTERY));
|
||||
this.setAlarming(MapUtils.getBoolean(body, Constant.ALARMING));
|
||||
this.setCharging(MapUtils.getBoolean(body, Constant.CHARGING));
|
||||
this.setRecording(MapUtils.getBoolean(body, Constant.RECORDING));
|
||||
|
||||
@@ -196,7 +196,7 @@ public class Room implements Closeable {
|
||||
@Override
|
||||
public void close() {
|
||||
log.info("关闭房间:{}", this.roomId);
|
||||
// TODO
|
||||
// TODO:关闭房间
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class MediaConsumeProtocol extends ProtocolRoomAdapter implements Applica
|
||||
|
||||
public static final String SIGNAL = "media::consume";
|
||||
|
||||
protected MediaConsumeProtocol() {
|
||||
public MediaConsumeProtocol() {
|
||||
super("消费媒体信令", SIGNAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MediaTransportWebRtcCreateProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
public static final String SIGNAL = "media::transport::webrtc::create";
|
||||
|
||||
protected MediaTransportWebRtcCreateProtocol() {
|
||||
public MediaTransportWebRtcCreateProtocol() {
|
||||
super("创建WebRTC通道信令", SIGNAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
}
|
||||
"""
|
||||
},
|
||||
flow = "终端->服务端->终端"
|
||||
flow = "终端->信令服务->终端"
|
||||
)
|
||||
public class PlatformScriptProtocol extends ProtocolClientAdapter {
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public class PlatformShutdownProtocol extends ProtocolClientAdapter implements C
|
||||
if(this.applicationContext instanceof ConfigurableApplicationContext context) {
|
||||
// API关闭
|
||||
if(context.isActive()) {
|
||||
// 如果需要完整广播可以设置延时
|
||||
// 如果需要广播完成可以设置延时
|
||||
context.close();
|
||||
} else {
|
||||
// 其他情况
|
||||
|
||||
@@ -19,16 +19,17 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID",
|
||||
...
|
||||
}
|
||||
""",
|
||||
flow = "终端->信令服务->终端"
|
||||
flow = "终端->信令服务-)终端"
|
||||
)
|
||||
public class RoomBroadcastProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
public static final String SIGNAL = "room::broadcast";
|
||||
|
||||
protected RoomBroadcastProtocol() {
|
||||
public RoomBroadcastProtocol() {
|
||||
super("房间广播信令", SIGNAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,36 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
*/
|
||||
@Protocol
|
||||
@Description(
|
||||
body = {
|
||||
"""
|
||||
{
|
||||
"roomId": "房间ID"
|
||||
}
|
||||
""",
|
||||
"""
|
||||
[
|
||||
{
|
||||
"ip": "终端IP",
|
||||
"name": "终端名称",
|
||||
"clientId": "终端ID",
|
||||
"clientType": "终端类型",
|
||||
"latitude": 纬度,
|
||||
"longitude": 经度,
|
||||
"humidity": 湿度,
|
||||
"temperature": 温度,
|
||||
"signal": 信号强度(0~100),
|
||||
"battery": 电池电量(0~100),
|
||||
"alarming": 是否发生告警(true|false),
|
||||
"charging": 是否正在充电(true|false),
|
||||
"recording": 是否正在录像(true|false),
|
||||
"lastHeartbeat": "最后心跳时间",
|
||||
"status": {更多状态},
|
||||
"config": {更多配置}
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
},
|
||||
flow = "终端=>信令服务->终端"
|
||||
)
|
||||
public class RoomClientListProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.Map;
|
||||
|
||||
import com.acgist.taoyao.boot.annotation.Description;
|
||||
import com.acgist.taoyao.boot.annotation.Protocol;
|
||||
import com.acgist.taoyao.boot.config.Constant;
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.signal.client.Client;
|
||||
import com.acgist.taoyao.signal.client.ClientType;
|
||||
@@ -17,6 +18,11 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
*/
|
||||
@Protocol
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端->信令服务->媒体服务->信令服务+)终端"
|
||||
)
|
||||
public class RoomCloseProtocol extends ProtocolRoomAdapter {
|
||||
@@ -29,9 +35,15 @@ public class RoomCloseProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Room room, Client client, Client mediaClient, Message message, Map<String, Object> body) {
|
||||
room.close();
|
||||
this.clientManager.broadcast(message);
|
||||
// TODO:释放房间
|
||||
if(clientType == ClientType.WEB) {
|
||||
mediaClient.push(this.build(Map.of(Constant.ROOM_ID, room.getRoomId())));
|
||||
} else if(clientType == ClientType.MEDIA) {
|
||||
room.close();
|
||||
room.broadcast(message);
|
||||
// TODO:移除
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,25 +16,30 @@ import com.acgist.taoyao.signal.event.MediaClientRegisterEvent;
|
||||
import com.acgist.taoyao.signal.party.media.Room;
|
||||
import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 创建房间信令
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
@Protocol
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"name": "房间名称",
|
||||
"passowrd": "房间密码",
|
||||
"mediaId": "媒体服务标识",
|
||||
"clientSize": "终端数量"
|
||||
}
|
||||
""",
|
||||
flow = "终端->服务端+)终端"
|
||||
body = {
|
||||
"""
|
||||
{
|
||||
"name": "房间名称",
|
||||
"passowrd": "房间密码(选填)",
|
||||
"mediaClientId": "媒体服务ID"
|
||||
}
|
||||
""",
|
||||
"""
|
||||
{
|
||||
"name": "房间名称",
|
||||
"clientSize": "终端数量",
|
||||
"mediaClientId": "媒体服务ID"
|
||||
}
|
||||
"""
|
||||
},
|
||||
flow = "终端->信令服务->媒体服务->信令服务+)终端"
|
||||
)
|
||||
public class RoomCreateProtocol extends ProtocolClientAdapter implements ApplicationListener<MediaClientRegisterEvent> {
|
||||
|
||||
@@ -53,19 +58,13 @@ public class RoomCreateProtocol extends ProtocolClientAdapter implements Applica
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
if(clientType == ClientType.WEB) {
|
||||
final String roomId = MapUtils.get(body, Constant.ROOM_ID);
|
||||
if (roomId != null && this.roomManager.room(roomId) != null) {
|
||||
log.info("房间已经存在:{}", roomId);
|
||||
return;
|
||||
}
|
||||
// 创建房间
|
||||
// WEB同步创建房间
|
||||
final Room room = this.roomManager.create(
|
||||
MapUtils.get(body, Constant.NAME),
|
||||
MapUtils.get(body, Constant.PASSWORD),
|
||||
MapUtils.get(body, Constant.MEDIA_ID),
|
||||
MapUtils.get(body, Constant.MEDIA_CLIENT_ID),
|
||||
message.cloneWithoutBody()
|
||||
);
|
||||
// 广播消息
|
||||
message.setBody(room.getRoomStatus());
|
||||
this.clientManager.broadcast(message);
|
||||
} else {
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.acgist.taoyao.signal.protocol.room;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.acgist.taoyao.boot.annotation.Description;
|
||||
import com.acgist.taoyao.boot.annotation.Protocol;
|
||||
import com.acgist.taoyao.boot.config.Constant;
|
||||
@@ -12,8 +14,8 @@ import com.acgist.taoyao.boot.utils.MapUtils;
|
||||
import com.acgist.taoyao.signal.client.Client;
|
||||
import com.acgist.taoyao.signal.client.ClientType;
|
||||
import com.acgist.taoyao.signal.party.media.ClientWrapper;
|
||||
import com.acgist.taoyao.signal.party.media.Room;
|
||||
import com.acgist.taoyao.signal.party.media.ClientWrapper.SubscribeType;
|
||||
import com.acgist.taoyao.signal.party.media.Room;
|
||||
import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -39,7 +41,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
}
|
||||
"""
|
||||
},
|
||||
flow = "终端->服务端-)终端"
|
||||
flow = "终端->信令服务-)终端"
|
||||
)
|
||||
public class RoomEnterProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
@@ -59,7 +61,7 @@ public class RoomEnterProtocol extends ProtocolRoomAdapter {
|
||||
final Object rtpCapabilities = MapUtils.get(body, Constant.RTP_CAPABILITIES);
|
||||
final Object sctpCapabilities = MapUtils.get(body, Constant.SCTP_CAPABILITIES);
|
||||
final String roomPassowrd = room.getPassword();
|
||||
if(roomPassowrd != null && !roomPassowrd.equals(password)) {
|
||||
if(StringUtils.isNotEmpty(roomPassowrd) && !roomPassowrd.equals(password)) {
|
||||
throw MessageCodeException.of(MessageCode.CODE_3401, "密码错误");
|
||||
}
|
||||
// 进入房间
|
||||
@@ -74,7 +76,7 @@ public class RoomEnterProtocol extends ProtocolRoomAdapter {
|
||||
));
|
||||
room.broadcast(message);
|
||||
log.info("进入房间:{} - {}", clientId, room.getRoomId());
|
||||
// 推送房间用户信息
|
||||
// 推送房间用户信息:TODO event
|
||||
final Message roomClientListMessage = this.roomClientListProtocol.build();
|
||||
roomClientListMessage.setBody(room.clientStatus());
|
||||
client.push(roomClientListMessage);
|
||||
|
||||
@@ -24,7 +24,29 @@ import lombok.Setter;
|
||||
* @author acgist
|
||||
*/
|
||||
@Protocol
|
||||
@Description
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"diskspace": [
|
||||
{
|
||||
"path": "存储路径",
|
||||
"free": 存储空闲,
|
||||
"total": 存储总量
|
||||
},
|
||||
...
|
||||
],
|
||||
"maxMemory": 最大能用内存,
|
||||
"freeMemory": 空闲内存,
|
||||
"totalMemory": 已用内存,
|
||||
"osArch": "系统架构",
|
||||
"osName": "系统名称",
|
||||
"osVersion": "系统版本",
|
||||
"javaVmName": "虚拟机名称",
|
||||
"javaVersion": "虚拟机版本",
|
||||
"cpuProcessors": CPU核心数量
|
||||
}
|
||||
"""
|
||||
)
|
||||
public class SystemInfoProtocol extends ProtocolClientAdapter {
|
||||
|
||||
public static final String SIGNAL = "system::info";
|
||||
@@ -38,10 +60,10 @@ public class SystemInfoProtocol extends ProtocolClientAdapter {
|
||||
final Map<String, Object> info = new HashMap<>();
|
||||
// 硬盘
|
||||
final List<Diskspace> diskspace = new ArrayList<>();
|
||||
// File.listRoots(); -> 不全
|
||||
// FileSystems.getDefault().getFileStores(); -> 重复
|
||||
// File.listRoots();
|
||||
// FileSystems.getDefault().getFileStores();
|
||||
Stream.of(File.listRoots()).forEach(v -> {
|
||||
diskspace.add(new Diskspace(v.getPath(), v.getTotalSpace(), v.getFreeSpace()));
|
||||
diskspace.add(new Diskspace(v.getPath(), v.getFreeSpace(), v.getTotalSpace()));
|
||||
});
|
||||
info.put("diskspace", diskspace);
|
||||
// 内存
|
||||
@@ -53,8 +75,8 @@ public class SystemInfoProtocol extends ProtocolClientAdapter {
|
||||
info.put("freeMemoryGracefully", FileUtils.formatSize(runtime.freeMemory()));
|
||||
info.put("totalMemoryGracefully", FileUtils.formatSize(runtime.totalMemory()));
|
||||
// 其他
|
||||
info.put("osName", System.getProperty("os.name"));
|
||||
info.put("osArch", System.getProperty("os.arch"));
|
||||
info.put("osName", System.getProperty("os.name"));
|
||||
info.put("osVersion", System.getProperty("os.version"));
|
||||
info.put("javaVmName", System.getProperty("java.vm.name"));
|
||||
info.put("javaVersion", System.getProperty("java.version"));
|
||||
@@ -71,10 +93,6 @@ public class SystemInfoProtocol extends ProtocolClientAdapter {
|
||||
* 路径
|
||||
*/
|
||||
private final String path;
|
||||
/**
|
||||
* 总量
|
||||
*/
|
||||
private final Long total;
|
||||
/**
|
||||
* 空闲
|
||||
*/
|
||||
@@ -82,18 +100,22 @@ public class SystemInfoProtocol extends ProtocolClientAdapter {
|
||||
/**
|
||||
* 总量
|
||||
*/
|
||||
private final String totalGracefully;
|
||||
private final Long total;
|
||||
/**
|
||||
* 空闲
|
||||
*/
|
||||
private final String freeGracefully;
|
||||
/**
|
||||
* 总量
|
||||
*/
|
||||
private final String totalGracefully;
|
||||
|
||||
public Diskspace(String path, Long total, Long free) {
|
||||
public Diskspace(String path, Long free, Long total) {
|
||||
this.path = path;
|
||||
this.total = total;
|
||||
this.free = free;
|
||||
this.totalGracefully = FileUtils.formatSize(total);
|
||||
this.total = total;
|
||||
this.freeGracefully = FileUtils.formatSize(free);
|
||||
this.totalGracefully = FileUtils.formatSize(total);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user