LINXD-2209: Refactor how we close the call; Check for callId in createRoom event
This commit is contained in:
parent
a51a757d17
commit
22e8b4d364
32
app.js
32
app.js
@ -99,6 +99,17 @@ const mediaCodecs = [
|
||||
},
|
||||
]
|
||||
|
||||
const closeCall = (callId) => {
|
||||
if (videoCalls[callId]) {
|
||||
videoCalls[callId].producer?.close();
|
||||
videoCalls[callId].consumer?.close();
|
||||
videoCalls[callId]?.consumerTransport.close();
|
||||
videoCalls[callId]?.producerTransport.close();
|
||||
videoCalls[callId].router.close();
|
||||
delete videoCalls[callId].router;
|
||||
}
|
||||
}
|
||||
|
||||
const getRtpCapabilities = (callId, callback) => {
|
||||
console.log('[getRtpCapabilities] callId', callId);
|
||||
const rtpCapabilities = videoCalls[callId].router.rtpCapabilities;
|
||||
@ -118,14 +129,18 @@ peers.on('connection', async socket => {
|
||||
})
|
||||
|
||||
socket.on('createRoom', async ({ callId }, callback) => {
|
||||
if (callId) {
|
||||
console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`);
|
||||
if (!videoCalls[callId]) {
|
||||
console.log('[createRoom] callId', callId);
|
||||
videoCalls[callId] = { router: await worker.createRouter({ mediaCodecs }) }
|
||||
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`)
|
||||
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`);
|
||||
}
|
||||
socketDetails[socket.id] = callId;
|
||||
getRtpCapabilities(callId, callback);
|
||||
} else {
|
||||
console.log(`[createRoom] missing callId ${callId}`);
|
||||
}
|
||||
})
|
||||
|
||||
// Client emits a request to create server side Transport
|
||||
@ -159,14 +174,9 @@ peers.on('connection', async socket => {
|
||||
console.log(`[transport-produce] Producer ID: ${videoCalls[callId].producer.id} | kind: ${videoCalls[callId].producer.kind}`)
|
||||
|
||||
videoCalls[callId].producer.on('transportclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('transport for this producer closed', callId)
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#producer-close
|
||||
videoCalls[callId].producer.close()
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-close
|
||||
videoCalls[callId].router.close()
|
||||
delete videoCalls[callId]
|
||||
closeCall(callId);
|
||||
})
|
||||
})
|
||||
|
||||
@ -200,7 +210,6 @@ peers.on('connection', async socket => {
|
||||
console.log('transport close from consumer', callId)
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-close
|
||||
stvideoCallsate[callId].router.close()
|
||||
videoCalls[callId].producer.close()
|
||||
videoCalls[callId].consumer.close()
|
||||
delete videoCalls[callId].router
|
||||
@ -211,10 +220,7 @@ peers.on('connection', async socket => {
|
||||
console.log('producer of consumer closed', callId)
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-close
|
||||
videoCalls[callId].router.close()
|
||||
videoCalls[callId].producer.close()
|
||||
videoCalls[callId].consumer.close()
|
||||
delete videoCalls[callId].router
|
||||
closeCall()
|
||||
})
|
||||
|
||||
// from the consumer extract the following params
|
||||
|
Loading…
Reference in New Issue
Block a user