LH-276: Add close-producer event handler; Update client #30

Merged
sergiu merged 9 commits from LH-276-close-producer into develop 2023-02-23 09:46:42 +00:00
Showing only changes of commit 6e3ce9fbb3 - Show all commits

27
app.js
View File

@ -389,19 +389,32 @@ peers.on('connection', async (socket) => {
try { try {
const callId = socketDetails[socket.id]; const callId = socketDetails[socket.id];
const socketId = socket.id; const socketId = socket.id;
let audioParams, videoParams;
console.log(`[consume] socket ${socket.id} | callId: ${callId}`); console.log(`[consume] socket ${socketId} | callId: ${callId}`);
if (typeof rtpCapabilities === 'string') rtpCapabilities = JSON.parse(rtpCapabilities); if (typeof rtpCapabilities === 'string') rtpCapabilities = JSON.parse(rtpCapabilities);
callback({
videoParams: await consumeVideo({ callId, socketId, rtpCapabilities }),
audioParams: await consumeAudio({ callId, socketId, rtpCapabilities }),
});
} catch (error) { } catch (error) {
console.error(`[consume] | ERROR | callId: ${socketDetails[socket.id]} | error: ${error.message}`); console.error(`[consume] | ERROR | callId: ${callId} | error: ${error.message}`);
callback({ params: { error } }); callback({ params: { error } });
} }
try {
videoParams = await consumeVideo({ callId, socketId, rtpCapabilities });
} catch (error) {
console.error(`[consume] | ERROR | videoParams | callId: ${callId} | error: ${error.message}`);
}
try {
audioParams = await consumeAudio({ callId, socketId, rtpCapabilities });
} catch (error) {
console.error(`[consume] | ERROR | audioParams | callId: ${callId} | error: ${error.message}`);
}
callback({
videoParams,
audioParams,
});
}); });
  • we should not use the same variables for both receiver and initiator, we can improve the naming with something like canConsumeAudioReceiver and canConsumeAudioInitiator
  • the assignments for canConsumeAudio and canConsumeVideo are very similar and very hard to distinguish if something is wrong, extract it in a function and use it in all 4 places
    • something like: initCanConsume(producer, callId, rtpCapabilities)
  • not sure if !! is necessary in all places
* we should not use the same variables for both receiver and initiator, we can improve the naming with something like `canConsumeAudioReceiver` and `canConsumeAudioInitiator` * the assignments for `canConsumeAudio` and `canConsumeVideo` are very similar and very hard to distinguish if something is wrong, extract it in a function and use it in all 4 places * something like: `initCanConsume(producer, callId, rtpCapabilities)` * not sure if `!!` is necessary in all places
/* /*