[*] 日常优化
This commit is contained in:
@@ -1310,20 +1310,22 @@ class Taoyao {
|
|||||||
/**
|
/**
|
||||||
* 关闭数据生产者信令
|
* 关闭数据生产者信令
|
||||||
*
|
*
|
||||||
* @param {*} message 消息
|
* @param {*} message 信令消息
|
||||||
* @param {*} body 消息主体
|
* @param {*} body 消息主体
|
||||||
*/
|
*/
|
||||||
async mediaDataProducerClose(message, body) {
|
async mediaDataProducerClose(message, body) {
|
||||||
const me = this;
|
const {
|
||||||
const { roomId, producerId } = body;
|
roomId,
|
||||||
const room = me.rooms.get(roomId);
|
producerId
|
||||||
|
} = body;
|
||||||
|
const room = this.rooms.get(roomId);
|
||||||
const dataProducer = room?.dataProducers.get(producerId);
|
const dataProducer = room?.dataProducers.get(producerId);
|
||||||
if(dataProducer) {
|
if(!dataProducer) {
|
||||||
console.info("关闭数据生产者", producerId);
|
console.debug("关闭数据生产者(数据生产者无效)", roomId, producerId);
|
||||||
await dataProducer.close();
|
return;
|
||||||
} else {
|
|
||||||
console.info("关闭数据生产者(无效)", producerId);
|
|
||||||
}
|
}
|
||||||
|
console.debug("关闭数据生产者", producerId);
|
||||||
|
await dataProducer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1755,38 +1755,6 @@ class Taoyao extends RemoteClient {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 关闭数据生产者信令
|
|
||||||
*
|
|
||||||
* @param {*} producerId 数据生产者ID
|
|
||||||
*/
|
|
||||||
mediaDataProducerClose(producerId) {
|
|
||||||
this.push(
|
|
||||||
protocol.buildMessage("media::data::producer::close", {
|
|
||||||
roomId : this.roomId,
|
|
||||||
producerId: producerId
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关闭数据生产者信令
|
|
||||||
*
|
|
||||||
* @param {*} message 信令消息
|
|
||||||
*/
|
|
||||||
defaultMediaDataProducerClose(message) {
|
|
||||||
const me = this;
|
|
||||||
const { roomId, producerId } = message.body;
|
|
||||||
const producer = me.getProducer(producerId);
|
|
||||||
if (producer) {
|
|
||||||
console.debug("关闭数据生产者", producerId);
|
|
||||||
producer.close();
|
|
||||||
me.dataProducer = null;
|
|
||||||
} else {
|
|
||||||
console.debug("关闭数据生产者无效", producerId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费媒体信令
|
* 消费媒体信令
|
||||||
*
|
*
|
||||||
@@ -2043,6 +2011,36 @@ class Taoyao extends RemoteClient {
|
|||||||
this.mediaDataProducerClose(this.dataProducer?.id);
|
this.mediaDataProducerClose(this.dataProducer?.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭数据生产者信令
|
||||||
|
*
|
||||||
|
* @param {*} producerId 数据生产者ID
|
||||||
|
*/
|
||||||
|
mediaDataProducerClose(producerId) {
|
||||||
|
this.push(protocol.buildMessage("media::data::producer::close", {
|
||||||
|
producerId,
|
||||||
|
roomId: this.roomId,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭数据生产者信令
|
||||||
|
*
|
||||||
|
* @param {*} message 信令消息
|
||||||
|
*/
|
||||||
|
defaultMediaDataProducerClose(message) {
|
||||||
|
const {
|
||||||
|
producerId
|
||||||
|
} = message.body;
|
||||||
|
const producer = this.getProducer(producerId);
|
||||||
|
if(!producer) {
|
||||||
|
console.debug("关闭数据生产者(数据生产者无效)", producerId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.debug("关闭数据生产者", producerId);
|
||||||
|
producer.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询数据生产者状态信令
|
* 查询数据生产者状态信令
|
||||||
*
|
*
|
||||||
@@ -2416,13 +2414,6 @@ class Taoyao extends RemoteClient {
|
|||||||
}
|
}
|
||||||
console.debug("关闭生产者", producerId);
|
console.debug("关闭生产者", producerId);
|
||||||
producer.close();
|
producer.close();
|
||||||
if(producer.kind === "audio") {
|
|
||||||
this.audioProducer = null;
|
|
||||||
} else if(producer.kind === "video") {
|
|
||||||
this.videoProducer = null;
|
|
||||||
} else {
|
|
||||||
console.warn("关闭生产者(生产者类型不支持)", producerId, producer.kind);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class MediaDataProducerCloseProtocol extends ProtocolRoomAdapter implemen
|
|||||||
@Async
|
@Async
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(MediaDataProducerCloseEvent event) {
|
public void onApplicationEvent(MediaDataProducerCloseEvent event) {
|
||||||
final Room room = event.getRoom();
|
final Room room = event.getRoom();
|
||||||
final Client mediaClient = event.getMediaClient();
|
final Client mediaClient = event.getMediaClient();
|
||||||
final Map<String, Object> body = Map.of(
|
final Map<String, Object> body = Map.of(
|
||||||
Constant.ROOM_ID, room.getRoomId(),
|
Constant.ROOM_ID, room.getRoomId(),
|
||||||
@@ -58,7 +58,7 @@ public class MediaDataProducerCloseProtocol extends ProtocolRoomAdapter implemen
|
|||||||
|
|
||||||
@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) {
|
||||||
final String producerId = MapUtils.get(body, Constant.PRODUCER_ID);
|
final String producerId = MapUtils.get(body, Constant.PRODUCER_ID);
|
||||||
final DataProducer dataProducer = room.dataProducer(producerId);
|
final DataProducer dataProducer = room.dataProducer(producerId);
|
||||||
if(dataProducer == null) {
|
if(dataProducer == null) {
|
||||||
log.debug("数据生产者无效:{} - {}", producerId, clientType);
|
log.debug("数据生产者无效:{} - {}", producerId, clientType);
|
||||||
|
|||||||
Reference in New Issue
Block a user