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