[*] 日常优化
This commit is contained in:
@@ -3,6 +3,7 @@ package com.acgist.taoyao.signal.party.room;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.signal.client.Client;
|
||||
import com.acgist.taoyao.signal.party.media.Consumer;
|
||||
import com.acgist.taoyao.signal.party.media.DataConsumer;
|
||||
@@ -118,6 +119,26 @@ public class ClientWrapper implements AutoCloseable {
|
||||
.anyMatch(v -> v.getDataProducer() == dataProducer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送消息
|
||||
*
|
||||
* @param message 消息
|
||||
*/
|
||||
public void push(Message message) {
|
||||
this.client.push(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求消息
|
||||
*
|
||||
* @param message 请求
|
||||
*
|
||||
* @return 响应
|
||||
*/
|
||||
public Message request(Message message) {
|
||||
return this.client.request(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// 注意:不要关闭终端(只是离开房间)
|
||||
|
||||
@@ -27,15 +27,17 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
@Protocol
|
||||
@Description(
|
||||
memo = "关闭通过回调实现所以不能同步响应",
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID"
|
||||
"roomId" : "房间ID"
|
||||
"consumerId": "消费者ID"
|
||||
}
|
||||
""",
|
||||
flow = {
|
||||
"媒体服务->信令服务-)终端",
|
||||
"终端->信令服务->媒体服务->信令服务+)终端"
|
||||
"媒体服务->信令服务->终端",
|
||||
"信令服务->媒体服务->信令服务->终端",
|
||||
"终端->信令服务->媒体服务->信令服务->终端"
|
||||
}
|
||||
)
|
||||
public class MediaConsumerCloseProtocol extends ProtocolRoomAdapter implements ApplicationListener<MediaConsumerCloseEvent> {
|
||||
@@ -69,9 +71,8 @@ public class MediaConsumerCloseProtocol extends ProtocolRoomAdapter implements A
|
||||
if(clientType.mediaClient()) {
|
||||
consumer.close();
|
||||
} else if(clientType.mediaServer()) {
|
||||
// TODO:路由到真实消费者
|
||||
consumer.remove();
|
||||
room.broadcast(message);
|
||||
consumer.getConsumerClient().push(message);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
|
||||
@@ -17,20 +17,23 @@ import com.acgist.taoyao.signal.party.media.Consumer;
|
||||
import com.acgist.taoyao.signal.party.room.Room;
|
||||
import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 暂停消费者信令
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
@Protocol
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID"
|
||||
"roomId" : "房间ID"
|
||||
"consumerId": "消费者ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
||||
flow = "终端=>信令服务->媒体服务"
|
||||
)
|
||||
public class MediaConsumerPauseProtocol extends ProtocolRoomAdapter implements ApplicationListener<MediaConsumerPauseEvent> {
|
||||
|
||||
@@ -54,13 +57,16 @@ public class MediaConsumerPauseProtocol extends ProtocolRoomAdapter implements A
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Room room, Client client, Client mediaClient, Message message, Map<String, Object> body) {
|
||||
final String consumerId = MapUtils.get(body, Constant.CONSUMER_ID);
|
||||
final Consumer consumer = room.consumer(consumerId);
|
||||
if(consumer == null) {
|
||||
log.debug("消费者无效:{} - {}", consumerId, clientType);
|
||||
return;
|
||||
}
|
||||
if(clientType.mediaClient()) {
|
||||
final String consumerId = MapUtils.get(body, Constant.CONSUMER_ID);
|
||||
final Consumer consumer = room.consumer(consumerId);
|
||||
consumer.pause();
|
||||
} else if(clientType.mediaServer()) {
|
||||
// TODO:路由到真实消费者
|
||||
room.broadcast(message);
|
||||
consumer.getConsumerClient().push(message);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID",
|
||||
"roomId" : "房间ID",
|
||||
"consumerId": "消费者ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
||||
flow = "终端->信令服务->媒体服务"
|
||||
)
|
||||
public class MediaConsumerRequestKeyFrameProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
|
||||
@@ -17,20 +17,23 @@ import com.acgist.taoyao.signal.party.media.Consumer;
|
||||
import com.acgist.taoyao.signal.party.room.Room;
|
||||
import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 恢复消费者信令
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
@Protocol
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID"
|
||||
"roomId" : "房间ID"
|
||||
"consumerId": "消费者ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
||||
flow = "终端=>信令服务->媒体服务"
|
||||
)
|
||||
public class MediaConsumerResumeProtocol extends ProtocolRoomAdapter implements ApplicationListener<MediaConsumerResumeEvent> {
|
||||
|
||||
@@ -54,13 +57,16 @@ public class MediaConsumerResumeProtocol extends ProtocolRoomAdapter implements
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Room room, Client client, Client mediaClient, Message message, Map<String, Object> body) {
|
||||
final String consumerId = MapUtils.get(body, Constant.CONSUMER_ID);
|
||||
final Consumer consumer = room.consumer(consumerId);
|
||||
if(consumer == null) {
|
||||
log.debug("消费者无效:{} - {}", consumerId, clientType);
|
||||
return;
|
||||
}
|
||||
if(clientType.mediaClient()) {
|
||||
final String consumerId = MapUtils.get(body, Constant.CONSUMER_ID);
|
||||
final Consumer consumer = room.consumer(consumerId);
|
||||
consumer.resume();
|
||||
} else if(clientType.mediaServer()) {
|
||||
// TODO:路由到真实消费者
|
||||
room.broadcast(message);
|
||||
consumer.getConsumerClient().push(message);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user