[*] 日常优化
This commit is contained in:
@@ -453,6 +453,9 @@ class Taoyao {
|
||||
case "media::producer::resume":
|
||||
me.mediaProducerResume(message, body);
|
||||
break;
|
||||
case "media::producer::status":
|
||||
me.mediaProducerStatus(message, body);
|
||||
break;
|
||||
case "media::router::rtp::capabilities":
|
||||
me.mediaRouterRtpCapabilities(message, body);
|
||||
break;
|
||||
@@ -800,12 +803,20 @@ class Taoyao {
|
||||
*/
|
||||
async mediaIceRestart(message, body) {
|
||||
const me = this;
|
||||
const { roomId, transportId } = body;
|
||||
const room = me.rooms.get(roomId);
|
||||
const transport = room?.transports.get(transportId);
|
||||
const iceParameters = await transport.restartIce();
|
||||
message.body.iceParameters = iceParameters;
|
||||
me.push(message);
|
||||
const {
|
||||
roomId,
|
||||
transportId
|
||||
} = body;
|
||||
const room = me.rooms.get(roomId);
|
||||
const transport = room?.transports.get(transportId);
|
||||
if(transport) {
|
||||
console.debug("重启ICE", transportId);
|
||||
const iceParameters = await transport.restartIce();
|
||||
message.body.iceParameters = iceParameters;
|
||||
me.push(message);
|
||||
} else {
|
||||
console.warn("重启ICE(无效)", transportId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -988,6 +999,32 @@ class Taoyao {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询生产者状态信令
|
||||
*
|
||||
* @param {*} message 信令消息
|
||||
* @param {*} body 消息主体
|
||||
*/
|
||||
async mediaProducerStatus(message, body) {
|
||||
const me = this;
|
||||
const {
|
||||
roomId,
|
||||
producerId,
|
||||
} = body;
|
||||
const room = me.rooms.get(roomId);
|
||||
const producer = room?.producers.get(producerId);
|
||||
if(producer) {
|
||||
console.debug("查询生产者状态", producerId);
|
||||
message.body = {
|
||||
...body,
|
||||
status: await producer.getStats()
|
||||
};
|
||||
me.push(message);
|
||||
} else {
|
||||
console.debug("查询生产者状态(无效)", producerId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 消费媒体信令
|
||||
*
|
||||
|
||||
@@ -840,6 +840,9 @@ class Taoyao extends RemoteClient {
|
||||
case "media::producer::resume":
|
||||
me.defaultMediaProducerResume(message);
|
||||
break;
|
||||
case "media::producer::score":
|
||||
me.defaultMediaProducerScore(message);
|
||||
break;
|
||||
case "media::video::orientation::change":
|
||||
me.defaultMediaVideoOrientationChange(message);
|
||||
break;
|
||||
@@ -1461,7 +1464,7 @@ class Taoyao extends RemoteClient {
|
||||
*
|
||||
* @param {*} consumerId 消费者ID
|
||||
*/
|
||||
async mediaConsumerPause(consumerId) {
|
||||
mediaConsumerPause(consumerId) {
|
||||
const me = this;
|
||||
const consumer = me.consumers.get(consumerId);
|
||||
if(consumer) {
|
||||
@@ -1469,7 +1472,7 @@ class Taoyao extends RemoteClient {
|
||||
return;
|
||||
}
|
||||
console.debug("暂停消费者", consumerId);
|
||||
await me.request(protocol.buildMessage("media::consumer::pause", {
|
||||
me.push(protocol.buildMessage("media::consumer::pause", {
|
||||
roomId : me.roomId,
|
||||
consumerId: consumerId,
|
||||
}));
|
||||
@@ -1525,7 +1528,7 @@ class Taoyao extends RemoteClient {
|
||||
*
|
||||
* @param {*} consumerId 消费者ID
|
||||
*/
|
||||
async mediaConsumerResume(consumerId) {
|
||||
mediaConsumerResume(consumerId) {
|
||||
const me = this;
|
||||
const consumer = me.consumers.get(consumerId);
|
||||
if(consumer) {
|
||||
@@ -1533,7 +1536,7 @@ class Taoyao extends RemoteClient {
|
||||
return;
|
||||
}
|
||||
console.debug("恢复消费者", consumerId);
|
||||
await me.request(protocol.buildMessage("media::consumer::resume", {
|
||||
me.push(protocol.buildMessage("media::consumer::resume", {
|
||||
roomId : me.roomId,
|
||||
consumerId: consumerId,
|
||||
}));
|
||||
@@ -1719,6 +1722,29 @@ class Taoyao extends RemoteClient {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启ICE信令
|
||||
*/
|
||||
async mediaIceRestart() {
|
||||
const me = this;
|
||||
if (me.sendTransport) {
|
||||
const response = await me.request(protocol.buildMessage("media::ice::restart", {
|
||||
roomId : me.roomId,
|
||||
transportId: me.sendTransport.id
|
||||
}));
|
||||
const { iceParameters } = response.body;
|
||||
await me.sendTransport.restartIce({ iceParameters });
|
||||
}
|
||||
if (me.recvTransport) {
|
||||
const response = await me.request(protocol.buildMessage("media::ice::restart", {
|
||||
roomId : me.roomId,
|
||||
transportId: me.recvTransport.id
|
||||
}));
|
||||
const { iceParameters } = response.body;
|
||||
await me.recvTransport.restartIce({ iceParameters });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭生产者信令
|
||||
*
|
||||
@@ -1740,7 +1766,10 @@ class Taoyao extends RemoteClient {
|
||||
*/
|
||||
async defaultMediaProducerClose(message) {
|
||||
const me = this;
|
||||
const { roomId, producerId } = message.body;
|
||||
const {
|
||||
roomId,
|
||||
producerId
|
||||
} = message.body;
|
||||
const producer = me.getProducer(producerId);
|
||||
if (producer) {
|
||||
console.debug("关闭生产者", producerId);
|
||||
@@ -1785,7 +1814,10 @@ class Taoyao extends RemoteClient {
|
||||
*/
|
||||
async defaultMediaProducerPause(message) {
|
||||
const me = this;
|
||||
const { roomId, producerId } = message.body;
|
||||
const {
|
||||
roomId,
|
||||
producerId
|
||||
} = message.body;
|
||||
const producer = me.getProducer(producerId);
|
||||
if (producer) {
|
||||
console.debug("暂停生产者", producerId);
|
||||
@@ -1824,7 +1856,10 @@ class Taoyao extends RemoteClient {
|
||||
*/
|
||||
async defaultMediaProducerResume(message) {
|
||||
const me = this;
|
||||
const { roomId, producerId } = message.body;
|
||||
const {
|
||||
roomId,
|
||||
producerId
|
||||
} = message.body;
|
||||
const producer = me.getProducer(producerId);
|
||||
if (producer) {
|
||||
console.debug("恢复生产者", producerId);
|
||||
@@ -1834,6 +1869,15 @@ class Taoyao extends RemoteClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 媒体生产者评分信令
|
||||
*
|
||||
* @param {*} message 信令消息
|
||||
*/
|
||||
defaultMediaProducerScore(message) {
|
||||
console.debug("生产者评分", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询生产者状态信令
|
||||
*
|
||||
@@ -1847,27 +1891,6 @@ class Taoyao extends RemoteClient {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启ICE信令
|
||||
*/
|
||||
async mediaIceRestart() {
|
||||
const me = this;
|
||||
if (me.sendTransport) {
|
||||
const response = await me.request(protocol.buildMessage('media::ice::restart', {
|
||||
transportId: me.sendTransport.id
|
||||
}));
|
||||
const { iceParameters } = response.body;
|
||||
await me.sendTransport.restartIce({ iceParameters });
|
||||
}
|
||||
if (me.recvTransport) {
|
||||
const response = await me.request(protocol.buildMessage('media::ice::restart', {
|
||||
transportId: me.recvTransport.id
|
||||
}));
|
||||
const { iceParameters } = response;
|
||||
await me.recvTransport.restartIce({ iceParameters });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 视频方向变化信令
|
||||
*
|
||||
@@ -2873,29 +2896,6 @@ class Taoyao extends RemoteClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启ICE信令
|
||||
*/
|
||||
async restartIce() {
|
||||
const me = this;
|
||||
if (me.sendTransport) {
|
||||
const response = await me.request("media::ice::restart", {
|
||||
roomId : me.roomId,
|
||||
transportId: me.sendTransport.id,
|
||||
});
|
||||
const iceParameters = response.data.iceParameters;
|
||||
await me.sendTransport.restartIce({ iceParameters });
|
||||
}
|
||||
if (me.recvTransport) {
|
||||
const response = await me.request("media::ice::restart", {
|
||||
roomId : me.roomId,
|
||||
transportId: me.recvTransport.id,
|
||||
});
|
||||
const iceParameters = response.data.iceParameters;
|
||||
await me.recvTransport.restartIce({ iceParameters });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起会话
|
||||
*
|
||||
|
||||
@@ -33,7 +33,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
"consumerId": "消费者ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端=>信令服务->媒体服务"
|
||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
||||
)
|
||||
public class MediaConsumerPauseProtocol extends ProtocolRoomAdapter implements ApplicationListener<MediaConsumerPauseEvent> {
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
"consumerId": "消费者ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端=>信令服务->媒体服务"
|
||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
||||
)
|
||||
public class MediaConsumerResumeProtocol extends ProtocolRoomAdapter implements ApplicationListener<MediaConsumerResumeEvent> {
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
}
|
||||
}
|
||||
""",
|
||||
flow = "媒体服务->信令服务->终端"
|
||||
flow = "媒体服务->信令服务+)终端"
|
||||
)
|
||||
public class MediaConsumerScoreProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
|
||||
@@ -20,19 +20,19 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
body = {
|
||||
"""
|
||||
{
|
||||
"roomId": "房间标识",
|
||||
"roomId" : "房间标识",
|
||||
"transportId": "通道标识"
|
||||
}
|
||||
""",
|
||||
"""
|
||||
{
|
||||
"roomId": "房间标识",
|
||||
"transportId": "通道标识",
|
||||
"roomId" : "房间标识",
|
||||
"transportId" : "通道标识",
|
||||
"iceParameters": "iceParameters"
|
||||
}
|
||||
"""
|
||||
},
|
||||
flow = "终端=>信令服务->媒体服务->信令服务->终端"
|
||||
flow = "终端=>信令服务->媒体服务"
|
||||
)
|
||||
public class MediaIceRestartProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ import lombok.extern.slf4j.Slf4j;
|
||||
body = {
|
||||
"""
|
||||
{
|
||||
"kind": "媒体类型",
|
||||
"roomId": "房间标识",
|
||||
"transportId": "通道标识",
|
||||
"kind" : "媒体类型",
|
||||
"roomId" : "房间标识",
|
||||
"transportId" : "通道标识",
|
||||
"rtpParameters": "rtpParameters"
|
||||
}
|
||||
"""
|
||||
},
|
||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
||||
flow = "终端=>信令服务->媒体服务"
|
||||
)
|
||||
public class MediaProduceProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
|
||||
@@ -27,13 +27,14 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
@Protocol
|
||||
@Description(
|
||||
memo = "关闭通过回调实现所以不能同步响应",
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID"
|
||||
"roomId" : "房间ID"
|
||||
"consumerId": "生产者ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端->信令服务->媒体服务->信令服务+)终端"
|
||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
||||
)
|
||||
public class MediaProducerCloseProtocol extends ProtocolRoomAdapter implements ApplicationListener<MediaProducerCloseEvent> {
|
||||
|
||||
@@ -49,7 +50,7 @@ public class MediaProducerCloseProtocol extends ProtocolRoomAdapter implements A
|
||||
final Room room = event.getRoom();
|
||||
final Client mediaClient = event.getMediaClient();
|
||||
final Map<String, Object> body = Map.of(
|
||||
Constant.ROOM_ID, room.getRoomId(),
|
||||
Constant.ROOM_ID, room.getRoomId(),
|
||||
Constant.PRODUCER_ID, event.getProducerId()
|
||||
);
|
||||
mediaClient.push(this.build(body));
|
||||
@@ -66,9 +67,8 @@ public class MediaProducerCloseProtocol extends ProtocolRoomAdapter implements A
|
||||
if(clientType.mediaClient()) {
|
||||
producer.close();
|
||||
} else if(clientType.mediaServer()) {
|
||||
// TODO:路由到真实消费者
|
||||
producer.remove();
|
||||
room.broadcast(message);
|
||||
producer.getProducerClient().push(message);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
|
||||
@@ -16,17 +16,20 @@ import com.acgist.taoyao.signal.party.media.Producer;
|
||||
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"
|
||||
"producerId": "消费者ID"
|
||||
"roomId" : "房间ID"
|
||||
"producerId": "生产者ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
||||
@@ -44,7 +47,7 @@ public class MediaProducerPauseProtocol extends ProtocolRoomAdapter implements A
|
||||
final Room room = event.getRoom();
|
||||
final Client mediaClient = event.getMediaClient();
|
||||
final Map<String, Object> body = Map.of(
|
||||
Constant.ROOM_ID, room.getRoomId(),
|
||||
Constant.ROOM_ID, room.getRoomId(),
|
||||
Constant.PRODUCER_ID, event.getProducerId()
|
||||
);
|
||||
mediaClient.push(this.build(body));
|
||||
@@ -52,13 +55,16 @@ public class MediaProducerPauseProtocol 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 producerId = MapUtils.get(body, Constant.PRODUCER_ID);
|
||||
final Producer producer = room.producer(producerId);
|
||||
if(producer == null) {
|
||||
log.debug("生产者无效:{} - {}", producerId, clientType);
|
||||
return;
|
||||
}
|
||||
if(clientType.mediaClient()) {
|
||||
final String producerId = MapUtils.get(body, Constant.PRODUCER_ID);
|
||||
final Producer producer = room.producer(producerId);
|
||||
producer.pause();
|
||||
} else if(clientType.mediaServer()) {
|
||||
// TODO:路由到真实消费者
|
||||
room.broadcast(message);
|
||||
producer.getProducerClient().push(message);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
|
||||
@@ -16,17 +16,20 @@ import com.acgist.taoyao.signal.party.media.Producer;
|
||||
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"
|
||||
"producerId": "消费者ID"
|
||||
"roomId" : "房间ID"
|
||||
"producerId": "生产者ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
||||
@@ -44,7 +47,7 @@ public class MediaProducerResumeProtocol extends ProtocolRoomAdapter implements
|
||||
final Room room = event.getRoom();
|
||||
final Client mediaClient = event.getMediaClient();
|
||||
final Map<String, Object> body = Map.of(
|
||||
Constant.ROOM_ID, room.getRoomId(),
|
||||
Constant.ROOM_ID, room.getRoomId(),
|
||||
Constant.PRODUCER_ID, event.getProducerId()
|
||||
);
|
||||
mediaClient.push(this.build(body));
|
||||
@@ -52,13 +55,16 @@ public class MediaProducerResumeProtocol 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 producerId = MapUtils.get(body, Constant.PRODUCER_ID);
|
||||
final Producer producer = room.producer(producerId);
|
||||
if(producer == null) {
|
||||
log.debug("生产者无效:{} - {}", producerId, clientType);
|
||||
return;
|
||||
}
|
||||
if(clientType.mediaClient()) {
|
||||
final String producerId = MapUtils.get(body, Constant.PRODUCER_ID);
|
||||
final Producer producer = room.producer(producerId);
|
||||
producer.resume();
|
||||
} else if(clientType.mediaServer()) {
|
||||
// TODO:路由到真实消费者
|
||||
room.broadcast(message);
|
||||
producer.getProducerClient().push(message);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,16 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
*/
|
||||
@Protocol
|
||||
@Description(
|
||||
flow = "媒体服务->信令服务->终端"
|
||||
body = """
|
||||
{
|
||||
"roomId" : "房间ID"
|
||||
"consumerId": "消费者ID"
|
||||
"score" : {
|
||||
...生产者评分
|
||||
}
|
||||
}
|
||||
""",
|
||||
flow = "媒体服务->信令服务+)终端"
|
||||
)
|
||||
public class MediaProducerScoreProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID",
|
||||
"roomId" : "房间ID",
|
||||
"producerId": "生产者ID"
|
||||
}
|
||||
""",
|
||||
flow = "终端=>信令服务->媒体服务->信令服务->终端"
|
||||
flow = "终端=>信令服务->媒体服务"
|
||||
)
|
||||
public class MediaProducerStatusProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user