LH-276: Update producer close event handler

This commit is contained in:
Sergiu Toma 2023-02-21 00:45:22 +02:00
parent 4b9987efe8
commit 512d0f8bed

109
app.js
View File

@ -227,17 +227,6 @@ peers.on('connection', async (socket) => {
videoCalls[callId].receiverProducerTransport = await createWebRtcTransportLayer(callId, callback); videoCalls[callId].receiverProducerTransport = await createWebRtcTransportLayer(callId, callback);
} else if (!videoCalls[callId].initiatorProducerTransport && isInitiator(callId, socket.id)) { } else if (!videoCalls[callId].initiatorProducerTransport && isInitiator(callId, socket.id)) {
videoCalls[callId].initiatorProducerTransport = await createWebRtcTransportLayer(callId, callback); videoCalls[callId].initiatorProducerTransport = await createWebRtcTransportLayer(callId, callback);
videoCalls[callId].initiatorProducerTransport.observer.on("newproducer", (producer) =>
{
console.log(
"------------------new producer created [worker.pid:%d, router.id:%s, transport.id:%s, producer.id:%s]", producer.id);
producer.observer.on("close", () => {
console.log("-------------------producer closed [producer.id:%s]", producer.id);
});
});
} else { } else {
console.log(`producerTransport has already been defined | callId ${callId}`); console.log(`producerTransport has already been defined | callId ${callId}`);
callback(null); callback(null);
@ -304,9 +293,10 @@ peers.on('connection', async (socket) => {
closeCall(callId); closeCall(callId);
}); });
videoCalls[callId].receiverVideoProducer.on('close', () => { videoCalls[callId].receiverVideoProducer.observer.on("close", () => {
console.log('receiverVideoProducer for this producer closed', callId); console.log(`[close-producer] receiverVideoProducer | callId: ${callId} | kind: ${kind}`);
}); videoCalls[callId].initiatorSocket.emit('close-producer', { callId, kind });
})
// Send back to the client the Producer's id // Send back to the client the Producer's id
callback && callback &&
@ -328,47 +318,11 @@ peers.on('connection', async (socket) => {
closeCall(callId); closeCall(callId);
}); });
console.log('🟢');
videoCalls[callId].initiatorVideoProducer.on('close', () => {
console.log('===================1 initiatorVideoProducer for this producer closed', callId);
});
videoCalls[callId].initiatorVideoProducer.observer.on("close", () => { videoCalls[callId].initiatorVideoProducer.observer.on("close", () => {
console.log('====================2 initiatorVideoProducer for this producer closed', callId); console.log(`[close-producer] initiatorVideoProducer | callId: ${callId} | kind: ${kind}`);
// const socketToEmit = isInitiator(callId, socket.id)
// ? videoCalls[callId].receiverSocket
// : videoCalls[callId].initiatorSocket;
// // callId - Id of the call
// // kind - producer type: audio/video
// socketToEmit.emit('new-producer', { callId, kind });
videoCalls[callId].receiverSocket.emit('close-producer', { callId, kind }); videoCalls[callId].receiverSocket.emit('close-producer', { callId, kind });
}) })
videoCalls[callId].initiatorVideoProducer.on('producerclose', () => {
console.log('000000000000000000000000000 producerclose initiatorVideoProducer!!!!!!!!!!!');
});
videoCalls[callId].initiatorVideoProducer.observer.on('producerclose', () => {
console.log('000000000000000000000000000 producerclose initiatorVideoProducer!!!!!!!!!!!');
});
videoCalls[callId].initiatorVideoProducer.on('closed', () => {
console.log('===================4 initiatorVideoProducer for this producer closed', callId);
});
videoCalls[callId].initiatorVideoProducer.observer.on("closed", () => {
console.log('====================5 initiatorVideoProducer for this producer closed', callId);
})
// videoCalls[callId].initiatorProducerTransport.observer.on("newproducer", (producer) =>
// {
// console.log(
// "new producer created [worker.pid:%d, router.id:%s, transport.id:%s, producer.id:%s]", producer.id);
// producer.observer.on("close", () => {
// console.log("producer closed [producer.id:%s]", producer.id);
// });
// });
callback && callback &&
callback({ callback({
id: videoCalls[callId].initiatorVideoProducer.id, id: videoCalls[callId].initiatorVideoProducer.id,
@ -390,9 +344,10 @@ peers.on('connection', async (socket) => {
closeCall(callId); closeCall(callId);
}); });
videoCalls[callId].receiverAudioProducer.on('close', () => { videoCalls[callId].receiverAudioProducer.observer.on("close", () => {
console.log('receiverAudioProducer for this producer closed', callId); console.log(`[close-producer] receiverAudioProducer | callId: ${callId} | kind: ${kind}`);
}); videoCalls[callId].initiatorSocket.emit('close-producer', { callId, kind });
})
// Send back to the client the Producer's id // Send back to the client the Producer's id
callback && callback &&
@ -414,9 +369,10 @@ peers.on('connection', async (socket) => {
closeCall(callId); closeCall(callId);
}); });
videoCalls[callId].initiatorAudioProducer.on('close', () => { videoCalls[callId].initiatorAudioProducer.observer.on("close", () => {
console.log('initiatorAudioProducer for this producer closed', callId); console.log(`[close-producer] initiatorAudioProducer | callId: ${callId} | kind: ${kind}`);
}); videoCalls[callId].initiatorSocket.emit('close-producer', { callId, kind });
})
// Send back to the client the Producer's id // Send back to the client the Producer's id
callback && callback &&
@ -583,15 +539,6 @@ const consumeVideo = async (callId, socketId, rtpCapabilities) => {
closeCall(callId); closeCall(callId);
}); });
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
videoCalls[callId].initiatorConsumerVideo.on('producerclose', () => {
console.log('000000000000000000000000000 producer of consumer closed', callId);
});
videoCalls[callId].initiatorConsumerTransport.on('producerclose', () => {
console.log('000000000000000000000000000 producerclose initiatorConsumerTransport');
});
return { return {
id: videoCalls[callId].initiatorConsumerVideo.id, id: videoCalls[callId].initiatorConsumerVideo.id,
producerId: videoCalls[callId].receiverVideoProducer.id, producerId: videoCalls[callId].receiverVideoProducer.id,
@ -611,12 +558,6 @@ const consumeVideo = async (callId, socketId, rtpCapabilities) => {
closeCall(callId); closeCall(callId);
}); });
videoCalls[callId].receiverConsumerVideo.on('producerclose', () => {
const callId = socketDetails[socket.id];
console.log('producer of consumer closed', callId);
closeCall(callId);
});
return { return {
id: videoCalls[callId].receiverConsumerVideo.id, id: videoCalls[callId].receiverConsumerVideo.id,
producerId: videoCalls[callId].initiatorVideoProducer.id, producerId: videoCalls[callId].initiatorVideoProducer.id,
@ -725,30 +666,6 @@ const createWebRtcTransportLayer = async (callId, callback) => {
console.log(`transport | closed | calldId ${callId}`); console.log(`transport | closed | calldId ${callId}`);
}); });
transport.observer.on("newdataproducer", (dataProducer) =>
{
console.log(
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^new data producer created [worker.pid:%d, router.id:%s, transport.id:%s, dataProducer.id:%s]",
worker.pid, router.id, transport.id, dataProducer.id);
dataProducer.observer.on("close", () =>
{
console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^data producer closed [dataProducer.id:%s]", dataProducer.id);
});
});
transport.observer.on("newproducer", (producer) =>
{
console.log(
"$$$$$$$$$$$$$$$$$$$$$$$$$$new producer created [worker.pid:%d, router.id:%s, transport.id:%s, producer.id:%s]",
worker.pid, router.id, transport.id, producer.id);
producer.observer.on("close", () =>
{
console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$producer closed [producer.id:%s]", producer.id);
});
});
const params = { const params = {
id: transport.id, id: transport.id,
iceParameters: transport.iceParameters, iceParameters: transport.iceParameters,