Update server

This commit is contained in:
Sergiu Toma 2022-11-29 02:34:48 +02:00
parent 38b95d5246
commit 46d3499e3d

134
app.js
View File

@ -366,79 +366,22 @@ peers.on('connection', async socket => {
console.log('🟠 videoCalls[callId].producerAudio', videoCalls[callId].producerAudio); console.log('🟠 videoCalls[callId].producerAudio', videoCalls[callId].producerAudio);
// Check if the router can consume the specified producer const canConsumeVideo = videoCalls[callId].producerVideo && videoCalls[callId].router.canConsume({
if (
videoCalls[callId].router.canConsume({
producerId: videoCalls[callId].producerVideo.id, producerId: videoCalls[callId].producerVideo.id,
rtpCapabilities rtpCapabilities
}) && })
videoCalls[callId].router.canConsume({
const canConsumeAudio = videoCalls[callId].producerAudio && videoCalls[callId].router.canConsume({
producerId: videoCalls[callId].producerAudio.id, producerId: videoCalls[callId].producerAudio.id,
rtpCapabilities rtpCapabilities
}) })
) {
console.log('[consume] Can consume', callId);
// Transport can now consume and return a consumer
videoCalls[callId].consumerVideo = await videoCalls[callId].consumerTransport.consume({
producerId: videoCalls[callId].producerVideo.id,
rtpCapabilities,
paused: true,
});
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose if (canConsumeVideo && !canConsumeAudio) {
videoCalls[callId].consumerVideo.on('transportclose', () => { const videoParams = consumeVideo()
const callId = socketDetails[socket.id]; callback({ videoParams, audioParams: null });
console.log('transport close from consumer', callId); } if (canConsumeVideo && canConsumeAudio) {
closeCall(callId); const videoParams = consumeVideo()
}); const audioParams = consumeAudio()
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
videoCalls[callId].consumerVideo.on('producerclose', () => {
const callId = socketDetails[socket.id];
console.log('producer of consumer closed', callId);
closeCall(callId);
});
// videoCalls[callId].consumerAudio = await videoCalls[callId].consumerTransport.consume({
// producerId: videoCalls[callId].producerAudio.id,
// rtpCapabilities,
// paused: true,
// });
// // https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
// videoCalls[callId].consumerAudio.on('transportclose', () => {
// const callId = socketDetails[socket.id];
// console.log('transport close from consumer', callId);
// closeCall(callId);
// });
// // https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
// videoCalls[callId].consumerAudio.on('producerclose', () => {
// const callId = socketDetails[socket.id];
// console.log('producer of consumer closed', callId);
// closeCall(callId);
// });
console.log('🟠 videoCalls[callId].consumerAudio', videoCalls[callId].consumerAudio);
// From the consumer extract the following params to send back to the Client
const videoParams = {
id: videoCalls[callId].consumerVideo.id,
producerId: videoCalls[callId].producerVideo.id,
kind: 'video',
rtpParameters: videoCalls[callId].consumerVideo.rtpParameters,
};
const audioParams = {
id: videoCalls[callId].consumerAudio.id,
producerId: videoCalls[callId].producerAudio.id,
kind: 'audio',
rtpParameters: videoCalls[callId].consumerAudio.rtpParameters,
};
console.log('[consume] videoParams', videoParams);
console.log('[consume] audioParams', audioParams);
// Send the parameters to the client
callback({ videoParams, audioParams }); callback({ videoParams, audioParams });
} else { } else {
console.log(`[canConsume] Can't consume | callId ${callId}`); console.log(`[canConsume] Can't consume | callId ${callId}`);
@ -466,6 +409,63 @@ peers.on('connection', async socket => {
}); });
}); });
const consumeVideo = async () => {
videoCalls[callId].consumerVideo = await videoCalls[callId].consumerTransport.consume({
producerId: videoCalls[callId].producerVideo.id,
rtpCapabilities,
paused: true,
});
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
videoCalls[callId].consumerVideo.on('transportclose', () => {
const callId = socketDetails[socket.id];
console.log('transport close from consumer', callId);
closeCall(callId);
});
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
videoCalls[callId].consumerVideo.on('producerclose', () => {
const callId = socketDetails[socket.id];
console.log('producer of consumer closed', callId);
closeCall(callId);
});
return {
id: videoCalls[callId].consumerVideo.id,
producerId: videoCalls[callId].producerVideo.id,
kind: 'video',
rtpParameters: videoCalls[callId].consumerVideo.rtpParameters,
}
}
const consumeAudio = async () => {
videoCalls[callId].consumerAudio = await videoCalls[callId].consumerTransport.consume({
producerId: videoCalls[callId].producerAudio.id,
rtpCapabilities,
paused: true,
});
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
videoCalls[callId].consumerAudio.on('transportclose', () => {
const callId = socketDetails[socket.id];
console.log('transport close from consumer', callId);
closeCall(callId);
});
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
videoCalls[callId].consumerAudio.on('producerclose', () => {
const callId = socketDetails[socket.id];
console.log('producer of consumer closed', callId);
closeCall(callId);
});
return {
id: videoCalls[callId].consumerAudio.id,
producerId: videoCalls[callId].producerAudio.id,
kind: 'audio',
rtpParameters: videoCalls[callId].consumerAudio.rtpParameters,
}
}
/* /*
- Called from at event 'createWebRtcTransport' and assigned to the consumer or producer transport - Called from at event 'createWebRtcTransport' and assigned to the consumer or producer transport
- It will return parameters, these are required for the client to create the RecvTransport - It will return parameters, these are required for the client to create the RecvTransport