[*] 优化Web SDK

This commit is contained in:
acgist
2023-09-15 08:30:35 +08:00
parent f0d728cf00
commit 64caae1ddd

View File

@@ -2100,12 +2100,7 @@ class Taoyao extends RemoteClient {
if(!audioTrack || !videoTrack) { if(!audioTrack || !videoTrack) {
await this.checkDevice(); await this.checkDevice();
} }
if(!this.sendTransport) { await this.mediaConnect();
await this.createSendTransport();
}
if(!this.recvTransport) {
await this.createRecvTransport();
}
await this.produceAudio(audioTrack); await this.produceAudio(audioTrack);
await this.produceVideo(videoTrack); await this.produceVideo(videoTrack);
await this.produceData(); await this.produceData();
@@ -2116,6 +2111,18 @@ class Taoyao extends RemoteClient {
} }
} }
/**
* 连接媒体
*/
async mediaConnect() {
if(!this.sendTransport) {
await this.createSendTransport();
}
if(!this.recvTransport) {
await this.createRecvTransport();
}
}
/** /**
* 生产音频 * 生产音频
* *
@@ -3672,18 +3679,33 @@ class Taoyao extends RemoteClient {
console.debug("关闭视频房间媒体"); console.debug("关闭视频房间媒体");
this.roomId = null; this.roomId = null;
await this.close(); await this.close();
this.consumers.forEach(async (consumer, consumerId) => { await this.closeRoomMediaConsumer();
await consumer.close(); await this.closeRoomMediaProducer();
}); await this.closeRoomMediaConnect();
this.consumers.clear(); this.closeFileVideo();
this.dataConsumers.forEach(async (dataConsumer, consumerId) => { }
await dataConsumer.close();
}); /**
this.dataConsumers.clear(); * 关闭媒体连接
this.remoteClients.forEach(async (remoteClient, clientId) => { */
await remoteClient.close(); async closeRoomMediaConnect() {
}); if (this.sendTransport) {
this.remoteClients.clear(); await this.sendTransport.close();
this.sendTransport = null;
}
if (this.recvTransport) {
await this.recvTransport.close();
this.recvTransport = null;
}
if(this.mediasoupDevice) {
this.mediasoupDevice = null;
}
}
/**
* 关闭媒体生产者
*/
async closeRoomMediaProducer() {
if(this.audioProducer) { if(this.audioProducer) {
await this.audioProducer.close(); await this.audioProducer.close();
this.audioProducer = null; this.audioProducer = null;
@@ -3696,18 +3718,24 @@ class Taoyao extends RemoteClient {
await this.dataProducer.close(); await this.dataProducer.close();
this.dataProducer = null; this.dataProducer = null;
} }
if (this.sendTransport) { }
await this.sendTransport.close();
this.sendTransport = null; /**
} * 关闭媒体消费者
if (this.recvTransport) { */
await this.recvTransport.close(); async closeRoomMediaConsumer() {
this.recvTransport = null; this.consumers.forEach(async (consumer, consumerId) => {
} await consumer.close();
if(this.mediasoupDevice) { });
this.mediasoupDevice = null; this.consumers.clear();
} this.dataConsumers.forEach(async (dataConsumer, consumerId) => {
this.closeFileVideo(); await dataConsumer.close();
});
this.dataConsumers.clear();
this.remoteClients.forEach(async (remoteClient, clientId) => {
await remoteClient.close();
});
this.remoteClients.clear();
} }
/** /**