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