[*] 日常优化
This commit is contained in:
@@ -26,52 +26,55 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
||||
body = {
|
||||
"""
|
||||
{
|
||||
"name": "房间名称",
|
||||
"passowrd": "房间密码(选填)",
|
||||
"name" : "房间名称",
|
||||
"passowrd" : "房间密码(选填)",
|
||||
"mediaClientId": "媒体服务ID"
|
||||
}
|
||||
""",
|
||||
"""
|
||||
{
|
||||
"name": "房间名称",
|
||||
"clientSize": "终端数量",
|
||||
"name" : "房间名称",
|
||||
"clientSize" : "终端数量",
|
||||
"mediaClientId": "媒体服务ID"
|
||||
}
|
||||
"""
|
||||
},
|
||||
flow = "终端->信令服务->媒体服务->信令服务+)终端"
|
||||
flow = {
|
||||
"终端=>信令服务->媒体服务",
|
||||
"终端->信令服务->媒体服务->信令服务-)终端"
|
||||
}
|
||||
)
|
||||
public class RoomCreateProtocol extends ProtocolClientAdapter implements ApplicationListener<MediaServerRegisterEvent> {
|
||||
|
||||
public static final String SIGNAL = "room::create";
|
||||
|
||||
public RoomCreateProtocol() {
|
||||
super("创建房间信令", SIGNAL);
|
||||
}
|
||||
public static final String SIGNAL = "room::create";
|
||||
|
||||
public RoomCreateProtocol() {
|
||||
super("创建房间信令", SIGNAL);
|
||||
}
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void onApplicationEvent(MediaServerRegisterEvent event) {
|
||||
this.roomManager.recreate(event.getClient(), this.build());
|
||||
// TODO:通知
|
||||
}
|
||||
@Async
|
||||
@Override
|
||||
public void onApplicationEvent(MediaServerRegisterEvent event) {
|
||||
this.roomManager.recreate(event.getClient(), this.build());
|
||||
// TODO:通知
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
if(clientType.mediaClient()) {
|
||||
// WEB同步创建房间
|
||||
final Room room = this.roomManager.create(
|
||||
MapUtils.get(body, Constant.NAME),
|
||||
MapUtils.get(body, Constant.PASSWORD),
|
||||
MapUtils.get(body, Constant.MEDIA_CLIENT_ID),
|
||||
message.cloneWithoutBody()
|
||||
if(clientType.mediaClient()) {
|
||||
// WEB同步创建房间
|
||||
final Room room = this.roomManager.create(
|
||||
MapUtils.get(body, Constant.NAME),
|
||||
MapUtils.get(body, Constant.PASSWORD),
|
||||
MapUtils.get(body, Constant.MEDIA_CLIENT_ID),
|
||||
message.cloneWithoutBody()
|
||||
);
|
||||
message.setBody(room.getRoomStatus());
|
||||
// 通知媒体终端
|
||||
this.clientManager.broadcast(message, ClientType.MEDIA_CLIENT_TYPE);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
message.setBody(room.getRoomStatus());
|
||||
// 通知媒体终端
|
||||
this.clientManager.broadcast(message, ClientType.MEDIA_CLIENT_TYPE);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,31 +29,34 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
body = {
|
||||
"""
|
||||
{
|
||||
"roomId": "房间ID",
|
||||
"roomId" : "房间ID",
|
||||
"password": "房间密码(选填)"
|
||||
}
|
||||
""",
|
||||
"""
|
||||
{
|
||||
"roomId": "房间标识",
|
||||
"roomId" : "房间标识",
|
||||
"clientId": "终端标识"
|
||||
}
|
||||
"""
|
||||
},
|
||||
flow = "终端->信令服务-)终端"
|
||||
flow = {
|
||||
"终端=>信令服务",
|
||||
"终端->信令服务-)终端"
|
||||
}
|
||||
)
|
||||
public class RoomEnterProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
public static final String SIGNAL = "room::enter";
|
||||
|
||||
public RoomEnterProtocol() {
|
||||
super("进入房间信令", SIGNAL);
|
||||
}
|
||||
public static final String SIGNAL = "room::enter";
|
||||
|
||||
public RoomEnterProtocol() {
|
||||
super("进入房间信令", SIGNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public boolean authenticate(Message message) {
|
||||
final Map<String, Object> body = message.body();
|
||||
final String roomId = MapUtils.get(body, Constant.ROOM_ID);
|
||||
final Map<String, Object> body = message.body();
|
||||
final String roomId = MapUtils.get(body, Constant.ROOM_ID);
|
||||
final String password = MapUtils.get(body, Constant.PASSWORD);
|
||||
final Room room = this.roomManager.getRoom(roomId);
|
||||
if(room == null) {
|
||||
@@ -65,30 +68,30 @@ public class RoomEnterProtocol extends ProtocolRoomAdapter {
|
||||
}
|
||||
throw MessageCodeException.of(MessageCode.CODE_3401, "密码错误");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public boolean authenticate(Room room, Client client) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Room room, Client client, Client mediaClient, Message message, Map<String, Object> body) {
|
||||
if(clientType.mediaClient()) {
|
||||
this.enter(clientId, room, client, message, body);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Room room, Client client, Client mediaClient, Message message, Map<String, Object> body) {
|
||||
if(clientType.mediaClient()) {
|
||||
this.enter(clientId, room, client, message, body);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端进入
|
||||
*
|
||||
* @param clientId 终端ID
|
||||
* @param room 房间
|
||||
* @param client 终端
|
||||
* @param message 消息
|
||||
* @param body 消息主体
|
||||
*/
|
||||
/**
|
||||
* 终端进入
|
||||
*
|
||||
* @param clientId 终端ID
|
||||
* @param room 房间
|
||||
* @param client 终端
|
||||
* @param message 消息
|
||||
* @param body 消息主体
|
||||
*/
|
||||
private void enter(String clientId, Room room, Client client, Message message, Map<String, Object> body) {
|
||||
final String subscribeType = MapUtils.get(body, Constant.SUBSCRIBE_TYPE);
|
||||
final Object rtpCapabilities = MapUtils.get(body, Constant.RTP_CAPABILITIES);
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID",
|
||||
"roomId" : "房间ID",
|
||||
"clientId": "终端ID"
|
||||
}
|
||||
""",
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID",
|
||||
"roomId" : "房间ID",
|
||||
"clientId": "终端ID",
|
||||
"password": "密码(选填)"
|
||||
}
|
||||
|
||||
@@ -19,27 +19,28 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
||||
body = """
|
||||
[
|
||||
{
|
||||
"name": "房间名称",
|
||||
"passowrd": "房间密码",
|
||||
"clientSize": "终端数量",
|
||||
"name" : "房间名称",
|
||||
"passowrd" : "房间密码",
|
||||
"clientSize" : "终端数量",
|
||||
"mediaClientId": "媒体服务标识"
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
""",
|
||||
flow = "终端=>信令服务"
|
||||
)
|
||||
public class RoomListProtocol extends ProtocolClientAdapter {
|
||||
|
||||
public static final String SIGNAL = "room::list";
|
||||
|
||||
public RoomListProtocol() {
|
||||
super("房间列表信令", SIGNAL);
|
||||
}
|
||||
public static final String SIGNAL = "room::list";
|
||||
|
||||
public RoomListProtocol() {
|
||||
super("房间列表信令", SIGNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
message.setBody(this.roomManager.getStatus());
|
||||
client.push(message);
|
||||
}
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
message.setBody(this.roomManager.getStatus());
|
||||
client.push(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
@Protocol
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID"
|
||||
}
|
||||
{
|
||||
"name" : "房间名称",
|
||||
"passowrd" : "房间密码",
|
||||
@@ -25,7 +28,7 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
"mediaClientId": "媒体服务标识"
|
||||
}
|
||||
""",
|
||||
flow = "终端=>信令服务->终端"
|
||||
flow = "终端=>信令服务"
|
||||
)
|
||||
public class RoomStatusProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user