Update server
This commit is contained in:
parent
cd84c534ce
commit
8444809910
100
app.js
100
app.js
@ -160,8 +160,11 @@ const mediaCodecs = [
|
|||||||
const closeCall = (callId) => {
|
const closeCall = (callId) => {
|
||||||
try {
|
try {
|
||||||
if (callId && videoCalls[callId]) {
|
if (callId && videoCalls[callId]) {
|
||||||
videoCalls[callId].producer?.close();
|
videoCalls[callId].producerVideo?.close();
|
||||||
videoCalls[callId].consumer?.close();
|
videoCalls[callId].producerAudio?.close();
|
||||||
|
videoCalls[callId].consumerVideo?.close();
|
||||||
|
videoCalls[callId].consumerAudio?.close();
|
||||||
|
|
||||||
videoCalls[callId]?.consumerTransport?.close();
|
videoCalls[callId]?.consumerTransport?.close();
|
||||||
videoCalls[callId]?.producerTransport?.close();
|
videoCalls[callId]?.producerTransport?.close();
|
||||||
videoCalls[callId]?.router?.close();
|
videoCalls[callId]?.router?.close();
|
||||||
@ -289,13 +292,17 @@ peers.on('connection', async socket => {
|
|||||||
console.log(`[transport-produce] kind: ${kind} | socket.id: ${socket.id} | callId: ${callId}`);
|
console.log(`[transport-produce] kind: ${kind} | socket.id: ${socket.id} | callId: ${callId}`);
|
||||||
console.log('kind', kind);
|
console.log('kind', kind);
|
||||||
console.log('rtpParameters', rtpParameters);
|
console.log('rtpParameters', rtpParameters);
|
||||||
videoCalls[callId].producer = await videoCalls[callId].producerTransport.produce({
|
|
||||||
|
if (kind === 'video') {
|
||||||
|
videoCalls[callId].producerVideo = await videoCalls[callId].producerTransport.produce({
|
||||||
kind,
|
kind,
|
||||||
rtpParameters,
|
rtpParameters,
|
||||||
});
|
});
|
||||||
console.log(`[transport-produce] Producer ID: ${videoCalls[callId].producer.id} | kind: ${videoCalls[callId].producer.kind}`);
|
|
||||||
|
|
||||||
videoCalls[callId].producer.on('transportclose', () => {
|
|
||||||
|
console.log(`[transport-produce] Producer ID: ${videoCalls[callId].producerVideo.id} | kind: ${videoCalls[callId].producerVideo.kind}`);
|
||||||
|
|
||||||
|
videoCalls[callId].producerVideo.on('transportclose', () => {
|
||||||
const callId = socketDetails[socket.id];
|
const callId = socketDetails[socket.id];
|
||||||
console.log('transport for this producer closed', callId)
|
console.log('transport for this producer closed', callId)
|
||||||
closeCall(callId);
|
closeCall(callId);
|
||||||
@ -303,8 +310,27 @@ peers.on('connection', async socket => {
|
|||||||
|
|
||||||
// Send back to the client the Producer's id
|
// Send back to the client the Producer's id
|
||||||
callback && callback({
|
callback && callback({
|
||||||
id: videoCalls[callId].producer.id
|
id: videoCalls[callId].producerVideo.id
|
||||||
});
|
});
|
||||||
|
} else if (kind === 'audio') {
|
||||||
|
videoCalls[callId].producerAudio = await videoCalls[callId].producerTransport.produce({
|
||||||
|
kind,
|
||||||
|
rtpParameters,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`[transport-produce] Producer ID: ${videoCalls[callId].producerAudio.id} | kind: ${videoCalls[callId].producerAudio.kind}`);
|
||||||
|
|
||||||
|
videoCalls[callId].producerAudio.on('transportclose', () => {
|
||||||
|
const callId = socketDetails[socket.id];
|
||||||
|
console.log('transport for this producer closed', callId)
|
||||||
|
closeCall(callId);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Send back to the client the Producer's id
|
||||||
|
callback && callback({
|
||||||
|
id: videoCalls[callId].producerAudio.id
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`);
|
console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||||
}
|
}
|
||||||
@ -339,43 +365,79 @@ peers.on('connection', async socket => {
|
|||||||
console.log('[consume] callId', callId);
|
console.log('[consume] callId', callId);
|
||||||
|
|
||||||
// Check if the router can consume the specified producer
|
// Check if the router can consume the specified producer
|
||||||
if (videoCalls[callId].router.canConsume({
|
if (
|
||||||
producerId: videoCalls[callId].producer.id,
|
videoCalls[callId].router.canConsume({
|
||||||
|
producerId: videoCalls[callId].producerVideo.id,
|
||||||
rtpCapabilities
|
rtpCapabilities
|
||||||
})) {
|
}) &&
|
||||||
|
videoCalls[callId].router.canConsume({
|
||||||
|
producerId: videoCalls[callId].producerAudio.id,
|
||||||
|
rtpCapabilities
|
||||||
|
})
|
||||||
|
) {
|
||||||
console.log('[consume] Can consume', callId);
|
console.log('[consume] Can consume', callId);
|
||||||
// Transport can now consume and return a consumer
|
// Transport can now consume and return a consumer
|
||||||
videoCalls[callId].consumer = await videoCalls[callId].consumerTransport.consume({
|
videoCalls[callId].consumerVideo = await videoCalls[callId].consumerTransport.consume({
|
||||||
producerId: videoCalls[callId].producer.id,
|
producerId: videoCalls[callId].producerVideo.id,
|
||||||
rtpCapabilities,
|
rtpCapabilities,
|
||||||
paused: true,
|
paused: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
||||||
videoCalls[callId].consumer.on('transportclose', () => {
|
videoCalls[callId].consumerVideo.on('transportclose', () => {
|
||||||
const callId = socketDetails[socket.id];
|
const callId = socketDetails[socket.id];
|
||||||
console.log('transport close from consumer', callId);
|
console.log('transport close from consumer', callId);
|
||||||
closeCall(callId);
|
closeCall(callId);
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
|
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
|
||||||
videoCalls[callId].consumer.on('producerclose', () => {
|
videoCalls[callId].consumerVideo.on('producerclose', () => {
|
||||||
const callId = socketDetails[socket.id];
|
const callId = socketDetails[socket.id];
|
||||||
console.log('producer of consumer closed', callId);
|
console.log('producer of consumer closed', callId);
|
||||||
closeCall(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].consumerVideo', videoCalls[callId].consumerVideo);
|
||||||
|
console.log('🟠 videoCalls[callId].consumerAudio', videoCalls[callId].consumerAudio);
|
||||||
|
|
||||||
// From the consumer extract the following params to send back to the Client
|
// From the consumer extract the following params to send back to the Client
|
||||||
const params = {
|
const videoParams = {
|
||||||
id: videoCalls[callId].consumer.id,
|
id: videoCalls[callId].consumerVideo.id,
|
||||||
producerId: videoCalls[callId].producer.id,
|
producerId: videoCalls[callId].producerVideo.id,
|
||||||
kind: videoCalls[callId].consumer.kind,
|
kind: 'video',
|
||||||
rtpParameters: videoCalls[callId].consumer.rtpParameters,
|
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] params', params);
|
console.log('[consume] params', params);
|
||||||
// Send the parameters to the client
|
// Send the parameters to the client
|
||||||
callback({ params });
|
callback({ videoParams, audioParams });
|
||||||
} else {
|
} else {
|
||||||
console.log(`[canConsume] Can't consume | callId ${callId}`);
|
console.log(`[canConsume] Can't consume | callId ${callId}`);
|
||||||
callback(null);
|
callback(null);
|
||||||
|
Loading…
Reference in New Issue
Block a user