LINXD-2270: Remove commented code; Update comments/logs
This commit is contained in:
parent
f8fcfb3165
commit
c1fe524ec7
117
app.js
117
app.js
@ -52,13 +52,8 @@ const httpsServer = https.createServer(options, app);
|
||||
|
||||
const io = new Server(httpsServer, {
|
||||
allowEIO3: true,
|
||||
origins: ["*:*"],
|
||||
// allowRequest: (req, next) => {
|
||||
// console.log('req', req);
|
||||
// next(null, true)
|
||||
// }
|
||||
origins: ["*:*"]
|
||||
});
|
||||
// const io = new Server(server, { origins: '*:*', allowEIO3: true });
|
||||
|
||||
httpsServer.listen(process.env.PORT, () => {
|
||||
console.log('Video server listening on port:', process.env.PORT);
|
||||
@ -213,8 +208,6 @@ peers.on('connection', async socket => {
|
||||
} else {
|
||||
console.log(`[createRoom] missing callId ${callId}`);
|
||||
}
|
||||
console.log('🔴 isInitiator(callId, socket.id)', isInitiator(callId, socket.id));
|
||||
console.log('🟩 videoCalls[callId]', JSON.stringify(videoCalls[callId]));
|
||||
} catch (error) {
|
||||
console.log(`ERROR | createRoom | callId ${callId} | ${error.message}`);
|
||||
} finally {
|
||||
@ -224,7 +217,7 @@ peers.on('connection', async socket => {
|
||||
|
||||
/*
|
||||
- Client emits a request to create server side Transport
|
||||
- Depending on the sender, producerTransport or consumerTransport is created on that router
|
||||
- Depending on the sender, a producer or consumer is created is created on that router
|
||||
- It will return parameters, these are required for the client to create the RecvTransport
|
||||
from the client.
|
||||
- If the client is producer(sender: true) then it will use parameters for device.createSendTransport(params)
|
||||
@ -243,25 +236,12 @@ peers.on('connection', async socket => {
|
||||
console.log(`producerTransport has already been defined | callId ${callId}`);
|
||||
callback(null);
|
||||
}
|
||||
|
||||
// if (!videoCalls[callId].producerTransport) {
|
||||
// videoCalls[callId].producerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
// } else {
|
||||
// console.log(`producerTransport has already been defined | callId ${callId}`);
|
||||
// callback(null);
|
||||
// }
|
||||
} else if (!sender) {
|
||||
if(!videoCalls[callId].receiverConsumerTransport && !isInitiator(callId, socket.id)) {
|
||||
videoCalls[callId].receiverConsumerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
} else if(!videoCalls[callId].initiatorConsumerTransport && isInitiator(callId, socket.id)) {
|
||||
videoCalls[callId].initiatorConsumerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
}
|
||||
// if (!videoCalls[callId].consumerTransport) {
|
||||
// videoCalls[callId].consumerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
// } else {
|
||||
// console.log(`consumerTransport has already been defined | callId ${callId}`);
|
||||
// callback(null);
|
||||
// }
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`ERROR | createWebRtcTransport | callId ${socketDetails[socket.id]} | sender ${sender} | ${error.message}`);
|
||||
@ -284,38 +264,29 @@ peers.on('connection', async socket => {
|
||||
} else {
|
||||
await videoCalls[callId].initiatorProducerTransport.connect({ dtlsParameters });
|
||||
}
|
||||
// await videoCalls[callId].producerTransport.connect({ dtlsParameters });
|
||||
} catch (error) {
|
||||
console.log(`ERROR | transport-connect | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
- The event sent by the client (PRODUCER) after successfully connecting to producerTransport
|
||||
- For the router with the id callId, we make produce on producerTransport
|
||||
- The event sent by the client (PRODUCER) after successfully connecting to receiverProducerTransport/initiatorProducerTransport
|
||||
- For the router with the id callId, we make produce on receiverProducerTransport/initiatorProducerTransport
|
||||
- Create the handler on producer at the 'transportclose' event
|
||||
*/
|
||||
socket.on('transport-produce', async ({ kind, rtpParameters, appData }, callback) => {
|
||||
try {
|
||||
const callId = socketDetails[socket.id];
|
||||
if (typeof rtpParameters === 'string') rtpParameters = JSON.parse(rtpParameters);
|
||||
|
||||
console.log(`[transport-produce] kind: ${kind} | socket.id: ${socket.id} | callId: ${callId}`);
|
||||
console.log('kind', kind);
|
||||
console.log('rtpParameters', rtpParameters);
|
||||
console.log('isInitiator()', isInitiator(callId, socket.id));
|
||||
socket.on('transport-produce', async ({ kind, rtpParameters, appData }, callback) => {
|
||||
try {
|
||||
const callId = socketDetails[socket.id];
|
||||
if (typeof rtpParameters === 'string') rtpParameters = JSON.parse(rtpParameters);
|
||||
|
||||
console.log(`[transport-produce] kind: ${kind} | socket.id: ${socket.id} | callId: ${callId}`);
|
||||
if (kind === 'video') {
|
||||
if (!isInitiator(callId, socket.id)) {
|
||||
console.log('----------1');
|
||||
videoCalls[callId].receiverVideoProducer = await videoCalls[callId].receiverProducerTransport.produce({
|
||||
kind,
|
||||
rtpParameters,
|
||||
});
|
||||
// videoCalls[callId].producerVideo = await videoCalls[callId].producerTransport.produce({
|
||||
// kind,
|
||||
// rtpParameters,
|
||||
// });
|
||||
|
||||
|
||||
console.log(`[transport-produce] receiverVideoProducer Producer ID: ${videoCalls[callId].receiverVideoProducer.id} | kind: ${videoCalls[callId].receiverVideoProducer.kind}`);
|
||||
|
||||
videoCalls[callId].receiverVideoProducer.on('transportclose', () => {
|
||||
@ -323,27 +294,17 @@ peers.on('connection', async socket => {
|
||||
console.log('transport for this producer closed', callId)
|
||||
closeCall(callId);
|
||||
});
|
||||
// videoCalls[callId].producerVideo.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].receiverVideoProducer.id
|
||||
});
|
||||
// // Send back to the client the Producer's id
|
||||
// callback && callback({
|
||||
// id: videoCalls[callId].producerVideo.id
|
||||
// });
|
||||
} else {
|
||||
console.log('----------2');
|
||||
videoCalls[callId].initiatorVideoProducer = await videoCalls[callId].initiatorProducerTransport.produce({
|
||||
kind,
|
||||
rtpParameters,
|
||||
});
|
||||
|
||||
|
||||
console.log(`[transport-produce] initiatorVideoProducer Producer ID: ${videoCalls[callId].initiatorVideoProducer.id} | kind: ${videoCalls[callId].initiatorVideoProducer.kind}`);
|
||||
|
||||
videoCalls[callId].initiatorVideoProducer.on('transportclose', () => {
|
||||
@ -438,19 +399,10 @@ peers.on('connection', async socket => {
|
||||
producerId: videoCalls[callId].receiverVideoProducer.id,
|
||||
rtpCapabilities
|
||||
});
|
||||
// const canConsumeVideo = !!videoCalls[callId].producerVideo && !!videoCalls[callId].router.canConsume({
|
||||
// producerId: videoCalls[callId].producerVideo.id,
|
||||
// rtpCapabilities
|
||||
// })
|
||||
|
||||
canConsumeAudio = !!videoCalls[callId].receiverAudioProducer && !!videoCalls[callId].router.canConsume({
|
||||
producerId: videoCalls[callId].receiverAudioProducer.id,
|
||||
rtpCapabilities
|
||||
});
|
||||
// const canConsumeAudio = !!videoCalls[callId].producerAudio && !!videoCalls[callId].router.canConsume({
|
||||
// producerId: videoCalls[callId].producerAudio.id,
|
||||
// rtpCapabilities
|
||||
// })
|
||||
|
||||
} else {
|
||||
canConsumeVideo = !!videoCalls[callId].initiatorVideoProducer && !!videoCalls[callId].router.canConsume({
|
||||
@ -518,12 +470,6 @@ const consumeVideo = async (callId, socketId, rtpCapabilities) => {
|
||||
rtpCapabilities,
|
||||
paused: true,
|
||||
});
|
||||
|
||||
// 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].initiatorConsumerVideo.on('transportclose', () => {
|
||||
@ -532,13 +478,6 @@ const consumeVideo = async (callId, socketId, rtpCapabilities) => {
|
||||
closeCall(callId);
|
||||
});
|
||||
|
||||
// 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].initiatorConsumerVideo.on('producerclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
@ -546,25 +485,12 @@ const consumeVideo = async (callId, socketId, rtpCapabilities) => {
|
||||
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].initiatorConsumerVideo.id,
|
||||
producerId: videoCalls[callId].receiverVideoProducer.id,
|
||||
kind: 'video',
|
||||
rtpParameters: videoCalls[callId].initiatorConsumerVideo.rtpParameters,
|
||||
}
|
||||
// return {
|
||||
// id: videoCalls[callId].consumerVideo.id,
|
||||
// producerId: videoCalls[callId].producerVideo.id,
|
||||
// kind: 'video',
|
||||
// rtpParameters: videoCalls[callId].consumerVideo.rtpParameters,
|
||||
// }
|
||||
} else {
|
||||
videoCalls[callId].receiverConsumerVideo = await videoCalls[callId].receiverConsumerTransport.consume({
|
||||
producerId: videoCalls[callId].initiatorVideoProducer.id,
|
||||
@ -601,12 +527,6 @@ const consumeAudio = async (callId, socketId, rtpCapabilities) => {
|
||||
paused: true,
|
||||
});
|
||||
|
||||
// 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].initiatorConsumerAudio.on('transportclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
@ -614,25 +534,12 @@ const consumeAudio = async (callId, socketId, rtpCapabilities) => {
|
||||
closeCall(callId);
|
||||
});
|
||||
|
||||
// // 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].initiatorConsumerAudio.on('producerclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('producer of consumer closed', 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].initiatorConsumerAudio.id,
|
||||
|
Loading…
Reference in New Issue
Block a user