LH-276: Add close-producer event handler; Update client #30
35
app.js
35
app.js
@ -388,27 +388,14 @@ peers.on('connection', async (socket) => {
|
||||
socket.on('consume', async ({ rtpCapabilities }, callback) => {
|
||||
const callId = socketDetails[socket.id];
|
||||
const socketId = socket.id;
|
||||
let audioParams, videoParams;
|
||||
|
||||
console.log(`[consume] socket ${socketId} | callId: ${callId}`);
|
||||
|
||||
if (typeof rtpCapabilities === 'string') rtpCapabilities = JSON.parse(rtpCapabilities);
|
||||
|
||||
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,
|
||||
videoParams: await consumeVideo({ callId, socketId, rtpCapabilities }),
|
||||
audioParams: await consumeAudio({ callId, socketId, rtpCapabilities }),
|
||||
});
|
||||
});
|
||||
|
||||
@ -462,7 +449,7 @@ const canConsume = ({ callId, producerId, rtpCapabilities }) => {
|
||||
|
||||
const consumeVideo = async ({ callId, socketId, rtpCapabilities }) => {
|
||||
// Handlers for consumer transport https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
||||
if (isInitiator(callId, socketId)) {
|
||||
if (isInitiator(callId, socketId) && videoCalls[callId].receiverVideoProducer) {
|
||||
const producerId = videoCalls[callId].receiverVideoProducer.id;
|
||||
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
||||
|
||||
@ -478,7 +465,7 @@ const consumeVideo = async ({ callId, socketId, rtpCapabilities }) => {
|
||||
kind: 'video',
|
||||
rtpParameters: videoCalls[callId].initiatorConsumerVideo.rtpParameters,
|
||||
};
|
||||
} else {
|
||||
} else if (videoCalls[callId].initiatorVideoProducer) {
|
||||
const producerId = videoCalls[callId].initiatorVideoProducer.id;
|
||||
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
||||
|
||||
@ -494,6 +481,8 @@ const consumeVideo = async ({ callId, socketId, rtpCapabilities }) => {
|
||||
kind: 'video',
|
||||
rtpParameters: videoCalls[callId].receiverConsumerVideo.rtpParameters,
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@ -501,7 +490,6 @@ const consumeAudio = async ({ callId, socketId, rtpCapabilities }) => {
|
||||
try {
|
||||
// Handlers for consumer transport https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
||||
if (isInitiator(callId, socketId) && videoCalls[callId].receiverAudioProducer) {
|
||||
console.log('1videoCalls[callId].receiverAudioProducer', videoCalls[callId].receiverAudioProducer);
|
||||
const producerId = videoCalls[callId].receiverAudioProducer.id;
|
||||
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
||||
|
||||
@ -510,16 +498,14 @@ const consumeAudio = async ({ callId, socketId, rtpCapabilities }) => {
|
||||
rtpCapabilities,
|
||||
paused: true,
|
||||
});
|
||||
const returnData = {
|
||||
|
||||
return {
|
||||
id: videoCalls[callId].initiatorConsumerAudio.id,
|
||||
producerId,
|
||||
kind: 'audio',
|
||||
rtpParameters: videoCalls[callId].initiatorConsumerAudio.rtpParameters,
|
||||
};
|
||||
console.log('audio returnData', returnData);
|
||||
return returnData;
|
||||
} else if (videoCalls[callId].initiatorAudioProducer) {
|
||||
console.log('2videoCalls[callId].initiatorAudioProducer', videoCalls[callId].initiatorAudioProducer);
|
||||
const producerId = videoCalls[callId].initiatorAudioProducer.id;
|
||||
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
||||
|
||||
@ -528,14 +514,13 @@ const consumeAudio = async ({ callId, socketId, rtpCapabilities }) => {
|
||||
rtpCapabilities,
|
||||
paused: true,
|
||||
});
|
||||
const returnData = {
|
||||
|
||||
return {
|
||||
id: videoCalls[callId].receiverConsumerAudio.id,
|
||||
producerId,
|
||||
kind: 'audio',
|
||||
rtpParameters: videoCalls[callId].receiverConsumerAudio.rtpParameters,
|
||||
};
|
||||
console.log('audio returnData', returnData);
|
||||
return returnData;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user