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) => {
|
||||
try {
|
||||
if (callId && videoCalls[callId]) {
|
||||
videoCalls[callId].producer?.close();
|
||||
videoCalls[callId].consumer?.close();
|
||||
videoCalls[callId].producerVideo?.close();
|
||||
videoCalls[callId].producerAudio?.close();
|
||||
videoCalls[callId].consumerVideo?.close();
|
||||
videoCalls[callId].consumerAudio?.close();
|
||||
|
||||
videoCalls[callId]?.consumerTransport?.close();
|
||||
videoCalls[callId]?.producerTransport?.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('kind', kind);
|
||||
console.log('rtpParameters', rtpParameters);
|
||||
videoCalls[callId].producer = await videoCalls[callId].producerTransport.produce({
|
||||
|
||||
if (kind === 'video') {
|
||||
videoCalls[callId].producerVideo = await videoCalls[callId].producerTransport.produce({
|
||||
kind,
|
||||
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];
|
||||
console.log('transport for this producer closed', callId)
|
||||
closeCall(callId);
|
||||
@ -303,8 +310,27 @@ peers.on('connection', async socket => {
|
||||
|
||||
// Send back to the client the Producer's id
|
||||
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) {
|
||||
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);
|
||||
|
||||
// Check if the router can consume the specified producer
|
||||
if (videoCalls[callId].router.canConsume({
|
||||
producerId: videoCalls[callId].producer.id,
|
||||
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].consumer = await videoCalls[callId].consumerTransport.consume({
|
||||
producerId: videoCalls[callId].producer.id,
|
||||
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].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].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].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
|
||||
const params = {
|
||||
id: videoCalls[callId].consumer.id,
|
||||
producerId: videoCalls[callId].producer.id,
|
||||
kind: videoCalls[callId].consumer.kind,
|
||||
rtpParameters: videoCalls[callId].consumer.rtpParameters,
|
||||
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] params', params);
|
||||
// Send the parameters to the client
|
||||
callback({ params });
|
||||
callback({ videoParams, audioParams });
|
||||
} else {
|
||||
console.log(`[canConsume] Can't consume | callId ${callId}`);
|
||||
callback(null);
|
||||
|
Loading…
Reference in New Issue
Block a user