LH-276: Update producer close event handler

This commit is contained in:
Sergiu Toma 2023-02-21 00:10:28 +02:00
parent 189c262b32
commit 9560d33870
1 changed files with 20 additions and 1 deletions

21
app.js
View File

@ -528,7 +528,7 @@ peers.on('connection', async (socket) => {
socket.on('consumer-resume', () => {
try {
const callId = socketDetails[socket.id];
console.log(`[consumer-resume] callId ${callId}`);
console.log(`[consumer-resume] callId: ${callId}`);
if (isInitiator(callId, socket.id)) {
videoCalls[callId]?.initiatorConsumerVideo?.resume();
videoCalls[callId]?.initiatorConsumerAudio?.resume();
@ -540,6 +540,25 @@ peers.on('connection', async (socket) => {
console.log(`ERROR | consumer-resume | callId ${socketDetails[socket.id]} | ${error.message}`);
}
});
socket.on('close-producer', ({ callId, kind}) => {
try {
const callId = socketDetails[socket.id];
console.log(`[close-producer] callId: ${callId} | kind: kind`);
if (isInitiator(callId, socket.id)) {
console.log(`[close-producer] initiator`);
if (kind === 'video') videoCalls[callId].initiatorVideoProducer.close()
else if (kind === 'audio') videoCalls[callId].initiatorAudioProducer.close()
} else {
console.log(`[close-producer] receiver`);
if (kind === 'video') videoCalls[callId].receiverVideoProducer.close()
else if (kind === 'audio') videoCalls[callId].receiverAudioProducer.close()
}
} catch (error) {
console.log(`ERROR | consumer-resume | callId ${socketDetails[socket.id]} | ${error.message}`);
}
});
});
const consumeVideo = async (callId, socketId, rtpCapabilities) => {