When user network connection problem occur (lost socket connection and reconnect) then I close current transport and all producer, consumer. Then re-create again.
public async loadTransport(skipConsume: boolean = false): Promise<void> {
let routerRtpCapabilities: mediasoupClient.types.RtpCapabilities
= await this.socketService.sendRequest('getRouterRtpCapabilities', null);
routerRtpCapabilities.headerExtensions = routerRtpCapabilities.headerExtensions
.filter((ext) => ext.uri !== 'urn:3gpp:video-orientation');
if (!this.mediasoupDevice.loaded) {
await this.mediasoupDevice.load({ routerRtpCapabilities });
}
this.resetRoomTransports();
await Promise.all([
this.createProducerTransport(),
this.createConsumerTransport()
]).then(() => {
// console.log("@ create producer/consumer transport: DONE");
});
// console.log("@ load transport: DONE");
}
and
public resetRoomTransports(): void {
if (this._sendRestartIce && this._sendRestartIce.timer) clearTimeout(this._sendRestartIce.timer);
if (this._recvRestartIce && this._recvRestartIce.timer) clearTimeout(this._recvRestartIce.timer);
if (this.audioTransport.getValue()) {
this.latencyService.unSubscribe("audio", this.audioTransport.getValue());
}
if (this.producerVideo) {
this.producerVideo.close();
this.producerVideo = null;
this.localParticipantService.updateLocalProducer('', 'webcam');
}
if (this.producerAudio) {
this.producerAudio.close();
this.producerAudio = null;
this.localParticipantService.updateLocalProducer('','audio');
}
try {
if (this.producerTransport) {
this.producerTransport.close();
this.producerTransport = null;
}
if (this.consumerTransport) {
this.consumerTransport.close();
this.consumerTransport = null;
}
} catch(error) {
this.producerTransport = null;
this.consumerTransport = null;
}
}
And then, I got Error:
enter image description here
Can I reuse old media stream (transport, consumer, producer) when I switch network, reconnect socket? Or, is there anyway to fix error log above?