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', () => {
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]
}