LH-276: Fix video consume when initiator is not set yet(at start)
This commit is contained in:
parent
9b3f2f94c8
commit
4591617b1e
35
app.js
35
app.js
@ -388,27 +388,14 @@ peers.on('connection', async (socket) => {
|
|||||||
socket.on('consume', async ({ rtpCapabilities }, callback) => {
|
socket.on('consume', async ({ rtpCapabilities }, callback) => {
|
||||||
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 ${socketId} | 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);
|
||||||
|
|
||||||
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({
|
callback({
|
||||||
videoParams,
|
videoParams: await consumeVideo({ callId, socketId, rtpCapabilities }),
|
||||||
audioParams,
|
audioParams: await consumeAudio({ callId, socketId, rtpCapabilities }),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -462,7 +449,7 @@ const canConsume = ({ callId, producerId, rtpCapabilities }) => {
|
|||||||
|
|
||||||
const consumeVideo = async ({ callId, socketId, rtpCapabilities }) => {
|
const consumeVideo = async ({ callId, socketId, rtpCapabilities }) => {
|
||||||
// Handlers for consumer transport https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
// 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;
|
const producerId = videoCalls[callId].receiverVideoProducer.id;
|
||||||
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
||||||
|
|
||||||
@ -478,7 +465,7 @@ const consumeVideo = async ({ callId, socketId, rtpCapabilities }) => {
|
|||||||
kind: 'video',
|
kind: 'video',
|
||||||
rtpParameters: videoCalls[callId].initiatorConsumerVideo.rtpParameters,
|
rtpParameters: videoCalls[callId].initiatorConsumerVideo.rtpParameters,
|
||||||
};
|
};
|
||||||
} else {
|
} else if (videoCalls[callId].initiatorVideoProducer) {
|
||||||
const producerId = videoCalls[callId].initiatorVideoProducer.id;
|
const producerId = videoCalls[callId].initiatorVideoProducer.id;
|
||||||
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
||||||
|
|
||||||
@ -494,6 +481,8 @@ const consumeVideo = async ({ callId, socketId, rtpCapabilities }) => {
|
|||||||
kind: 'video',
|
kind: 'video',
|
||||||
rtpParameters: videoCalls[callId].receiverConsumerVideo.rtpParameters,
|
rtpParameters: videoCalls[callId].receiverConsumerVideo.rtpParameters,
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -501,7 +490,6 @@ const consumeAudio = async ({ callId, socketId, rtpCapabilities }) => {
|
|||||||
try {
|
try {
|
||||||
// Handlers for consumer transport https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
// Handlers for consumer transport https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
||||||
if (isInitiator(callId, socketId) && videoCalls[callId].receiverAudioProducer) {
|
if (isInitiator(callId, socketId) && videoCalls[callId].receiverAudioProducer) {
|
||||||
console.log('1videoCalls[callId].receiverAudioProducer', videoCalls[callId].receiverAudioProducer);
|
|
||||||
const producerId = videoCalls[callId].receiverAudioProducer.id;
|
const producerId = videoCalls[callId].receiverAudioProducer.id;
|
||||||
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
||||||
|
|
||||||
@ -510,16 +498,14 @@ const consumeAudio = async ({ callId, socketId, rtpCapabilities }) => {
|
|||||||
rtpCapabilities,
|
rtpCapabilities,
|
||||||
paused: true,
|
paused: true,
|
||||||
});
|
});
|
||||||
const returnData = {
|
|
||||||
|
return {
|
||||||
id: videoCalls[callId].initiatorConsumerAudio.id,
|
id: videoCalls[callId].initiatorConsumerAudio.id,
|
||||||
producerId,
|
producerId,
|
||||||
kind: 'audio',
|
kind: 'audio',
|
||||||
rtpParameters: videoCalls[callId].initiatorConsumerAudio.rtpParameters,
|
rtpParameters: videoCalls[callId].initiatorConsumerAudio.rtpParameters,
|
||||||
};
|
};
|
||||||
console.log('audio returnData', returnData);
|
|
||||||
return returnData;
|
|
||||||
} else if (videoCalls[callId].initiatorAudioProducer) {
|
} else if (videoCalls[callId].initiatorAudioProducer) {
|
||||||
console.log('2videoCalls[callId].initiatorAudioProducer', videoCalls[callId].initiatorAudioProducer);
|
|
||||||
const producerId = videoCalls[callId].initiatorAudioProducer.id;
|
const producerId = videoCalls[callId].initiatorAudioProducer.id;
|
||||||
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
if (!canConsume({ callId, producerId, rtpCapabilities })) return null;
|
||||||
|
|
||||||
@ -528,14 +514,13 @@ const consumeAudio = async ({ callId, socketId, rtpCapabilities }) => {
|
|||||||
rtpCapabilities,
|
rtpCapabilities,
|
||||||
paused: true,
|
paused: true,
|
||||||
});
|
});
|
||||||
const returnData = {
|
|
||||||
|
return {
|
||||||
id: videoCalls[callId].receiverConsumerAudio.id,
|
id: videoCalls[callId].receiverConsumerAudio.id,
|
||||||
producerId,
|
producerId,
|
||||||
kind: 'audio',
|
kind: 'audio',
|
||||||
rtpParameters: videoCalls[callId].receiverConsumerAudio.rtpParameters,
|
rtpParameters: videoCalls[callId].receiverConsumerAudio.rtpParameters,
|
||||||
};
|
};
|
||||||
console.log('audio returnData', returnData);
|
|
||||||
return returnData;
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user