Update server
This commit is contained in:
parent
38b95d5246
commit
46d3499e3d
142
app.js
142
app.js
@ -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 (
|
producerId: videoCalls[callId].producerVideo.id,
|
||||||
videoCalls[callId].router.canConsume({
|
rtpCapabilities
|
||||||
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,
|
|
||||||
});
|
|
||||||
|
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
const canConsumeAudio = videoCalls[callId].producerAudio && videoCalls[callId].router.canConsume({
|
||||||
videoCalls[callId].consumerVideo.on('transportclose', () => {
|
producerId: videoCalls[callId].producerAudio.id,
|
||||||
const callId = socketDetails[socket.id];
|
rtpCapabilities
|
||||||
console.log('transport close from consumer', callId);
|
})
|
||||||
closeCall(callId);
|
|
||||||
});
|
|
||||||
|
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
|
if (canConsumeVideo && !canConsumeAudio) {
|
||||||
videoCalls[callId].consumerVideo.on('producerclose', () => {
|
const videoParams = consumeVideo()
|
||||||
const callId = socketDetails[socket.id];
|
callback({ videoParams, audioParams: null });
|
||||||
console.log('producer of consumer closed', callId);
|
} if (canConsumeVideo && canConsumeAudio) {
|
||||||
closeCall(callId);
|
const videoParams = consumeVideo()
|
||||||
});
|
const audioParams = consumeAudio()
|
||||||
|
|
||||||
|
|
||||||
// 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
|
||||||
|
Loading…
Reference in New Issue
Block a user