Update server

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

142
app.js
View File

@ -366,79 +366,22 @@ peers.on('connection', async socket => {
console.log('🟠 videoCalls[callId].producerAudio', videoCalls[callId].producerAudio);
// Check if the router can consume the specified producer
if (
videoCalls[callId].router.canConsume({
producerId: videoCalls[callId].producerVideo.id,
rtpCapabilities
}) &&
videoCalls[callId].router.canConsume({
producerId: videoCalls[callId].producerAudio.id,
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,
});
const canConsumeVideo = videoCalls[callId].producerVideo && videoCalls[callId].router.canConsume({
producerId: videoCalls[callId].producerVideo.id,
rtpCapabilities
})
// 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);
});
const canConsumeAudio = videoCalls[callId].producerAudio && videoCalls[callId].router.canConsume({
producerId: videoCalls[callId].producerAudio.id,
rtpCapabilities
})
// 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
if (canConsumeVideo && !canConsumeAudio) {
const videoParams = consumeVideo()
callback({ videoParams, audioParams: null });
} if (canConsumeVideo && canConsumeAudio) {
const videoParams = consumeVideo()
const audioParams = consumeAudio()
callback({ videoParams, audioParams });
} else {
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
- It will return parameters, these are required for the client to create the RecvTransport