From 01fec638c90505afe373864bd051f6aa93aa326e Mon Sep 17 00:00:00 2001 From: Sergiu Toma Date: Thu, 11 Aug 2022 14:54:46 +0300 Subject: [PATCH] Refactor transportclose 13 --- app.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index a65df1e..c6d8834 100644 --- a/app.js +++ b/app.js @@ -159,8 +159,9 @@ peers.on('connection', async socket => { producer.on('transportclose', () => { console.log('transport for this producer closed ') - producer.close() - delete router[callId] + closeRoom(callId) + // producer.close() + // delete router[callId] }) // Send back to the client the Producer's id @@ -191,7 +192,8 @@ peers.on('connection', async socket => { consumer.on('transportclose', () => { console.log('transport close from consumer', callId) - delete router[callId] + closeRoom(callId) + // delete router[callId] }) consumer.on('producerclose', () => { @@ -275,4 +277,20 @@ const createWebRtcTransportLayer = async (callId, callback) => { } }) } +} + +const closeRoom = (callId) => { + // Close transport for producer/consumer +// https://mediasoup.org/documentation/v3/mediasoup-client/api/#Transport-methods +producerTransport.close() +consumerTransport.close() + +// Close producer and consumer +// https://mediasoup.org/documentation/v3/mediasoup-client/api/#producer-close +// https://mediasoup.org/documentation/v3/mediasoup-client/api/#consumer-closed +producer.close() +consumer.close() + +// Reset room +delete router[callId] } \ No newline at end of file