LINXD-2209-black-screen-when-2-video-calls-are-answered-simultaneously #3

Merged
sergiu merged 31 commits from LINXD-2209-black-screen-when-2-video-calls-are-answered-simultaneously into master 2022-09-15 14:49:55 +00:00
Showing only changes of commit 22e8b4d364 - Show all commits

44
app.js
View File

@ -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;
}
}

not important: we don't need socket.id on clients

not important: we don't need socket.id on clients
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) => {
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}`)
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}`);
}
socketDetails[socket.id] = callId;
getRtpCapabilities(callId, callback);
cristi marked this conversation as resolved Outdated

For refactor: why do we need to differentiate between producerTransport and consumerTransport? Why don't we have a transport variable (it is only one transport for each client regardless if they are producer or consumer)?

For refactor: why do we need to differentiate between producerTransport and consumerTransport? Why don't we have a `transport` variable (it is only one transport for each client regardless if they are producer or consumer)?

We need producer and consumer transports for each call.

We need producer and consumer transports for each call.
} else {
console.log(`[createRoom] missing callId ${callId}`);
}
socketDetails[socket.id] = callId;
getRtpCapabilities(callId, callback);
})
// 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