Refactor transportclose 13

This commit is contained in:
Sergiu Toma 2022-08-11 14:54:46 +03:00
parent 6d8f22939a
commit 01fec638c9

24
app.js
View File

@ -159,8 +159,9 @@ peers.on('connection', async socket => {
producer.on('transportclose', () => { producer.on('transportclose', () => {
console.log('transport for this producer closed ') console.log('transport for this producer closed ')
producer.close() closeRoom(callId)
delete router[callId] // producer.close()
// delete router[callId]
}) })
// Send back to the client the Producer's id // Send back to the client the Producer's id
@ -191,7 +192,8 @@ peers.on('connection', async socket => {
consumer.on('transportclose', () => { consumer.on('transportclose', () => {
console.log('transport close from consumer', callId) console.log('transport close from consumer', callId)
delete router[callId] closeRoom(callId)
// delete router[callId]
}) })
consumer.on('producerclose', () => { consumer.on('producerclose', () => {
@ -276,3 +278,19 @@ 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]
}