[*] 日常优化
This commit is contained in:
@@ -1177,6 +1177,8 @@ class Taoyao {
|
||||
console.info("数据消费者关闭(生产者关闭)", dataConsumer.id, streamId);
|
||||
dataConsumer.close();
|
||||
});
|
||||
// dataConsumer.on("bufferedamountlow", fn(bufferedAmount));
|
||||
// dataConsumer.on("sctpsendbufferfull", fn());
|
||||
dataConsumer.observer.on("close", () => {
|
||||
if(room.dataConsumers.delete(dataConsumer.id)) {
|
||||
console.info("数据消费者关闭", dataConsumer.id, streamId);
|
||||
@@ -1232,23 +1234,22 @@ class Taoyao {
|
||||
* @param {*} body 消息主体
|
||||
*/
|
||||
async mediaDataConsumerStatus(message, body) {
|
||||
const me = this;
|
||||
const {
|
||||
roomId,
|
||||
consumerId,
|
||||
} = body;
|
||||
const room = me.rooms.get(roomId);
|
||||
const room = this.rooms.get(roomId);
|
||||
const dataConsumer = room?.dataConsumers.get(consumerId);
|
||||
if(dataConsumer) {
|
||||
if(!dataConsumer) {
|
||||
console.warn("查询数据消费者状态(数据消费者无效)", roomId, consumerId);
|
||||
return;
|
||||
}
|
||||
console.debug("查询数据消费者状态", consumerId);
|
||||
message.body = {
|
||||
...body,
|
||||
status: await dataConsumer.getStats()
|
||||
};
|
||||
me.push(message);
|
||||
} else {
|
||||
console.debug("查询数据消费者状态(无效)", consumerId);
|
||||
}
|
||||
this.push(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1742,19 +1742,6 @@ class Taoyao extends RemoteClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据消费者状态信令
|
||||
*
|
||||
* @param {*} consumerId 消费者ID
|
||||
*/
|
||||
async mediaDataConsumerStatus(consumerId) {
|
||||
const me = this;
|
||||
return await me.request(protocol.buildMessage("media::data::consumer::status", {
|
||||
roomId: me.roomId,
|
||||
consumerId
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 消费媒体信令
|
||||
*
|
||||
@@ -1928,50 +1915,64 @@ class Taoyao extends RemoteClient {
|
||||
dataConsumer.on("message", (message, ppid) => {
|
||||
console.debug("数据消费者消息", dataConsumer.id, streamId, message.toString("UTF-8"), ppid);
|
||||
});
|
||||
// dataConsumer.on("bufferedamountlow", fn(bufferedAmount));
|
||||
// dataConsumer.on("sctpsendbufferfull", fn());
|
||||
} catch (error) {
|
||||
console.error("打开数据消费者异常", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据消费者状态信令
|
||||
*
|
||||
* @param {*} consumerId 消费者ID
|
||||
*/
|
||||
async mediaDataConsumerStatus(consumerId) {
|
||||
return await this.request(protocol.buildMessage("media::data::consumer::status", {
|
||||
consumerId,
|
||||
roomId: this.roomId,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生产数据
|
||||
*/
|
||||
async produceData() {
|
||||
const me = this;
|
||||
if(me.dataProducer) {
|
||||
console.debug("已经存在视频生产者");
|
||||
if(this.dataProducer) {
|
||||
console.debug("已经存在数据生产者");
|
||||
return;
|
||||
}
|
||||
if(!me.dataProduce) {
|
||||
if(!this.dataProduce) {
|
||||
console.debug("不能生产数据");
|
||||
return;
|
||||
}
|
||||
const dataProducer = await me.sendTransport.produceData({
|
||||
this.dataProducer = await this.sendTransport.produceData({
|
||||
label : "taoyao",
|
||||
ordered : false,
|
||||
priority : "medium",
|
||||
// maxRetransmits: 1,
|
||||
maxPacketLifeTime: 2000,
|
||||
});
|
||||
me.dataProducer = dataProducer;
|
||||
me.dataProducer.on("transportclose", () => {
|
||||
console.debug("数据生产者关闭(通道关闭)", me.dataProducer.id);
|
||||
me.dataProducer.close();
|
||||
this.dataProducer.on("transportclose", () => {
|
||||
console.debug("数据生产者关闭(通道关闭)", this.dataProducer.id);
|
||||
this.dataProducer.close();
|
||||
});
|
||||
me.dataProducer.on("open", () => {
|
||||
console.debug("数据生产者打开", me.dataProducer.id);
|
||||
this.dataProducer.on("open", () => {
|
||||
console.debug("数据生产者打开", this.dataProducer.id);
|
||||
});
|
||||
me.dataProducer.on("close", () => {
|
||||
console.debug("数据生产者关闭", me.dataProducer.id);
|
||||
me.dataProducer = null;
|
||||
this.dataProducer.on("close", () => {
|
||||
console.debug("数据生产者关闭", this.dataProducer.id);
|
||||
this.dataProducer = null;
|
||||
});
|
||||
me.dataProducer.on("error", (error) => {
|
||||
console.debug("数据生产者异常", me.dataProducer.id, error);
|
||||
this.dataProducer.on("error", (error) => {
|
||||
console.debug("数据生产者异常", this.dataProducer.id, error);
|
||||
});
|
||||
// me.dataProducer.on("bufferedamountlow", fn(bufferedAmount));
|
||||
// me.dataProducer.on("sctpsendbufferfull", fn());
|
||||
// this.dataProducer.on("bufferedamountlow", fn(bufferedAmount));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭数据生产者
|
||||
*/
|
||||
async closeDataProducer() {
|
||||
this.mediaDataProducerClose(this.dataProducer?.id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1983,13 +1984,6 @@ class Taoyao extends RemoteClient {
|
||||
this.dataProducer?.send(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭数据生产者
|
||||
*/
|
||||
async closeDataProducer() {
|
||||
this.mediaDataProducerClose(this.dataProducer?.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭数据生产者信令
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user