LH-276: Update producer close event handler

This commit is contained in:
Sergiu Toma 2023-02-21 01:09:35 +02:00
parent 1060293980
commit cb14061b94

67
app.js
View File

@ -424,44 +424,44 @@ peers.on('connection', async (socket) => {
socket.on('consume', async ({ rtpCapabilities }, callback) => { socket.on('consume', async ({ rtpCapabilities }, callback) => {
try { try {
const callId = socketDetails[socket.id]; const callId = socketDetails[socket.id];
console.log(
`[consume] socket ${socket.id} | callId ${callId} | rtpCapabilities: ${JSON.stringify(rtpCapabilities)}`
);
if (typeof rtpCapabilities === 'string') rtpCapabilities = JSON.parse(rtpCapabilities); if (typeof rtpCapabilities === 'string') rtpCapabilities = JSON.parse(rtpCapabilities);
console.log('[consume] callId', callId);
let canConsumeVideo, canConsumeAudio; let canConsumeVideo, canConsumeAudio;
if (isInitiator(callId, socket.id)) { try {
canConsumeVideo = if (isInitiator(callId, socket.id)) {
!!videoCalls[callId].receiverVideoProducer && canConsumeVideo =
!!videoCalls[callId].router.canConsume({ !!videoCalls[callId].receiverVideoProducer &&
producerId: videoCalls[callId].receiverVideoProducer.id, !!videoCalls[callId].router.canConsume({
rtpCapabilities, producerId: videoCalls[callId].receiverVideoProducer.id,
}); rtpCapabilities,
canConsumeAudio = });
!!videoCalls[callId].receiverAudioProducer && canConsumeAudio =
!!videoCalls[callId].router.canConsume({ !!videoCalls[callId].receiverAudioProducer &&
producerId: videoCalls[callId].receiverAudioProducer.id, !!videoCalls[callId].router.canConsume({
rtpCapabilities, producerId: videoCalls[callId].receiverAudioProducer.id,
}); rtpCapabilities,
} else { });
canConsumeVideo = } else {
!!videoCalls[callId].initiatorVideoProducer && canConsumeVideo =
!!videoCalls[callId].router.canConsume({ !!videoCalls[callId].initiatorVideoProducer &&
producerId: videoCalls[callId].initiatorVideoProducer.id, !!videoCalls[callId].router.canConsume({
rtpCapabilities, producerId: videoCalls[callId].initiatorVideoProducer.id,
}); rtpCapabilities,
});
canConsumeAudio = canConsumeAudio =
!!videoCalls[callId].initiatorAudioProducer && !!videoCalls[callId].initiatorAudioProducer &&
!!videoCalls[callId].router.canConsume({ !!videoCalls[callId].router.canConsume({
producerId: videoCalls[callId].initiatorAudioProducer.id, producerId: videoCalls[callId].initiatorAudioProducer.id,
rtpCapabilities, rtpCapabilities,
}); });
}
} catch (error) {
console.error(`[consume] ERROR | callId: ${callId} | error: ${error.message}`)
} }
console.log('[consume] canConsumeVideo', canConsumeVideo);
console.log('[consume] canConsumeAudio', canConsumeAudio); console.log(`[consume] socket ${socket.id} | callId: ${callId} | canConsumeVideo: ${canConsumeVideo} | canConsumeAudio: ${canConsumeAudio}`);
if (canConsumeVideo && !canConsumeAudio) { if (canConsumeVideo && !canConsumeAudio) {
const videoParams = await consumeVideo(callId, socket.id, rtpCapabilities); const videoParams = await consumeVideo(callId, socket.id, rtpCapabilities);
@ -479,7 +479,7 @@ peers.on('connection', async (socket) => {
callback(null); callback(null);
} }
} catch (error) { } catch (error) {
console.log(`ERROR | consume | callId ${socketDetails[socket.id]} | ${error.message}`); console.error(`[consume] ERROR | callId: ${socketDetails[socket.id]} | error: ${error.message}`);
callback({ params: { error } }); callback({ params: { error } });
} }
}); });
@ -673,7 +673,6 @@ const createWebRtcTransportLayer = async (callId, callback) => {
dtlsParameters: transport.dtlsParameters, dtlsParameters: transport.dtlsParameters,
}; };
console.log('[createWebRtcTransportLayer] callback params', params);
// Send back to the client the params // Send back to the client the params
callback({ params }); callback({ params });