LH-276: Update producer close event handler

This commit is contained in:
Sergiu Toma 2023-02-21 02:06:09 +02:00
parent 48ef4911b1
commit 0fca614e8e

46
app.js
View File

@ -291,10 +291,10 @@ peers.on('connection', async (socket) => {
closeCall(callId);
});
videoCalls[callId].receiverVideoProducer.observer.on("close", () => {
console.log(`[close-producer] receiverVideoProducer receiver --EMIT--> initiator | callId: ${callId} | kind: ${kind}`);
videoCalls[callId].initiatorSocket.emit('close-producer', { callId, kind });
})
// videoCalls[callId].receiverVideoProducer.observer.on("close", () => {
// console.log(`[close-producer] receiverVideoProducer receiver --EMIT--> initiator | callId: ${callId} | kind: ${kind}`);
// videoCalls[callId].initiatorSocket.emit('close-producer', { callId, kind });
// })
// Send back to the client the Producer's id
callback &&
@ -316,10 +316,10 @@ peers.on('connection', async (socket) => {
closeCall(callId);
});
videoCalls[callId].initiatorVideoProducer.observer.on("close", () => {
console.log(`[close-producer] initiatorVideoProducer initiator --EMIT--> receiver | callId: ${callId} | kind: ${kind}`);
videoCalls[callId].receiverSocket.emit('close-producer', { callId, kind });
})
// videoCalls[callId].initiatorVideoProducer.observer.on("close", () => {
// console.log(`[close-producer] initiatorVideoProducer initiator --EMIT--> receiver | callId: ${callId} | kind: ${kind}`);
// videoCalls[callId].receiverSocket.emit('close-producer', { callId, kind });
// })
callback &&
callback({
@ -342,10 +342,10 @@ peers.on('connection', async (socket) => {
closeCall(callId);
});
videoCalls[callId].receiverAudioProducer.observer.on("close", () => {
console.log(`[close-producer] receiverAudioProducer receiver --EMIT--> initiator | callId: ${callId} | kind: ${kind}`);
videoCalls[callId].initiatorSocket.emit('close-producer', { callId, kind });
})
// videoCalls[callId].receiverAudioProducer.observer.on("close", () => {
// console.log(`[close-producer] receiverAudioProducer receiver --EMIT--> initiator | callId: ${callId} | kind: ${kind}`);
// videoCalls[callId].initiatorSocket.emit('close-producer', { callId, kind });
// })
// Send back to the client the Producer's id
callback &&
@ -367,10 +367,10 @@ peers.on('connection', async (socket) => {
closeCall(callId);
});
videoCalls[callId].initiatorAudioProducer.observer.on("close", () => {
console.log(`[close-producer] initiatorAudioProducer initiator --EMIT--> receiver | callId: ${callId} | kind: ${kind}`);
videoCalls[callId].receiverSocket.emit('close-producer', { callId, kind });
})
// videoCalls[callId].initiatorAudioProducer.observer.on("close", () => {
// console.log(`[close-producer] initiatorAudioProducer initiator --EMIT--> receiver | callId: ${callId} | kind: ${kind}`);
// videoCalls[callId].receiverSocket.emit('close-producer', { callId, kind });
// })
// Send back to the client the Producer's id
callback &&
@ -521,15 +521,19 @@ peers.on('connection', async (socket) => {
socket.on('close-producer', ({ callId, kind}) => {
try {
console.log(`[close-producer] callId: ${callId} | kind: ${kind}`);
// if (isInitiator(callId, socket.id)) {
// if (kind === 'video') videoCalls[callId].initiatorVideoProducer.close()
if (isInitiator(callId, socket.id)) {
// if (kind === 'video') {videoCalls[callId].initiatorVideoProducer.close()}
// else if (kind === 'audio') videoCalls[callId].initiatorAudioProducer.close()
// } else {
console.log(`[close-producer] initiator --EMIT--> receiver | callId: ${callId} | kind: ${kind}`);
videoCalls[callId].receiverSocket.emit('close-producer', { callId, kind });
} else {
// if (kind === 'video') videoCalls[callId].receiverVideoProducer.close()
// else if (kind === 'audio') videoCalls[callId].receiverAudioProducer.close()
// }
console.log(`[close-producer] receiver --EMIT--> initiator | callId: ${callId} | kind: ${kind}`);
videoCalls[callId].initiatorSocket.emit('close-producer', { callId, kind });
}
} catch (error) {
console.error(`[close-producer] | ERROR | callId ${socketDetails[socket.id]} | error: ${error.message}`);
console.error(`[close-producer] | ERROR | callId: ${socketDetails[socket.id]} | error: ${error.message}`);
}
});