LH-276: Update producer close event handler

This commit is contained in:
Sergiu Toma 2023-02-21 02:24:52 +02:00
parent f99a4d9849
commit 2afdf8b0ca

28
app.js
View File

@ -188,22 +188,21 @@ peers.on('connection', async (socket) => {
console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`);
if (!videoCalls[callId]) {
videoCalls[callId] = { router: await worker.createRouter({ mediaCodecs }) };
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`);
console.log(`[createRoom] Generate Router ID: ${videoCalls[callId].router.id}`);
videoCalls[callId].receiverSocket = socket;
} else {
videoCalls[callId].initiatorSocket = socket;
}
socketDetails[socket.id] = callId;
// rtpCapabilities is set for callback
console.log('[getRtpCapabilities] callId', callId);
callbackResponse = {
rtpCapabilities: videoCalls[callId].router.rtpCapabilities,
};
} else {
console.log(`[createRoom] missing callId ${callId}`);
console.log(`[createRoom] missing callId: ${callId}`);
}
} catch (error) {
console.error(`[createRoom] | ERROR | callId ${callId} | error: ${error.message}`);
console.error(`[createRoom] | ERROR | callId: ${callId} | error: ${error.message}`);
} finally {
callback(callbackResponse);
}
@ -272,7 +271,7 @@ peers.on('connection', async (socket) => {
const callId = socketDetails[socket.id];
if (typeof rtpParameters === 'string') rtpParameters = JSON.parse(rtpParameters);
console.log(`[transport-produce] kind: ${kind} | socket: ${socket.id} | callId: ${callId}`);
console.log(`[transport-produce] callId: ${callId} | kind: ${kind} | socket: ${socket.id}`);
if (kind === 'video') {
if (!isInitiator(callId, socket.id)) {
@ -281,10 +280,6 @@ peers.on('connection', async (socket) => {
rtpParameters,
});
console.log(
`[transport-produce] receiverVideoProducer Producer ID: ${videoCalls[callId].receiverVideoProducer.id} | kind: ${videoCalls[callId].receiverVideoProducer.kind}`
);
videoCalls[callId].receiverVideoProducer.on('transportclose', () => {
console.log('transport for this producer closed', callId);
closeCall(callId);
@ -301,10 +296,6 @@ peers.on('connection', async (socket) => {
rtpParameters,
});
console.log(
`[transport-produce] initiatorVideoProducer Producer ID: ${videoCalls[callId].initiatorVideoProducer.id} | kind: ${videoCalls[callId].initiatorVideoProducer.kind}`
);
videoCalls[callId].initiatorVideoProducer.on('transportclose', () => {
console.log('transport for this producer closed', callId);
closeCall(callId);
@ -322,10 +313,6 @@ peers.on('connection', async (socket) => {
rtpParameters,
});
console.log(
`[transport-produce] receiverAudioProducer Producer ID: ${videoCalls[callId].receiverAudioProducer.id} | kind: ${videoCalls[callId].receiverAudioProducer.kind}`
);
videoCalls[callId].receiverAudioProducer.on('transportclose', () => {
console.log('transport for this producer closed', callId);
closeCall(callId);
@ -342,10 +329,6 @@ peers.on('connection', async (socket) => {
rtpParameters,
});
console.log(
`[transport-produce] initiatorAudioProducer Producer ID: ${videoCalls[callId].initiatorAudioProducer.id} | kind: ${videoCalls[callId].initiatorAudioProducer.kind}`
);
videoCalls[callId].initiatorAudioProducer.on('transportclose', () => {
console.log('transport for this producer closed', callId);
closeCall(callId);
@ -485,7 +468,6 @@ 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)) {
console.log(`[close-producer] initiator --EMIT--> receiver | callId: ${callId} | kind: ${kind}`);
videoCalls[callId].receiverSocket.emit('close-producer', { callId, kind });
@ -574,7 +556,7 @@ const isInitiator = (callId, socketId) => {
*/
const createWebRtcTransportLayer = async (callId, callback) => {
try {
console.log('[createWebRtcTransportLayer] callId', callId);
console.log(`[createWebRtcTransportLayer] callId: ${callId}`);
// https://mediasoup.org/documentation/v3/mediasoup/api/#WebRtcTransportOptions
const webRtcTransport_options = {
listenIps: [