Compare commits

..

13 Commits

3 changed files with 35 additions and 14 deletions

View File

@ -33,3 +33,7 @@ producer = it will always be true because you are the producer
(it's possible to put false, but then you have to have another client with producer true) (it's possible to put false, but then you have to have another client with producer true)
assetName = asset name of the unit on which you are doing the test assetName = asset name of the unit on which you are doing the test
assetType = asset type of the unit on which you are doing the test assetType = asset type of the unit on which you are doing the test
### Demo project
The demo project used initially and then modified for our needs `https://github.com/jamalag/mediasoup2`

43
app.js
View File

@ -112,10 +112,12 @@ const closeCall = (callId) => {
if (videoCalls[callId]) { if (videoCalls[callId]) {
videoCalls[callId].producer?.close(); videoCalls[callId].producer?.close();
videoCalls[callId].consumer?.close(); videoCalls[callId].consumer?.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();
delete videoCalls[callId]; delete videoCalls[callId];
} else {
console.log(`The call with id ${callId} has already been deleted`);
} }
} catch (error) { } catch (error) {
console.log(`ERROR | closeCall | callid ${callId} | ${error.message}`); console.log(`ERROR | closeCall | callid ${callId} | ${error.message}`);
@ -146,8 +148,10 @@ peers.on('connection', async socket => {
// It is triggered when the peer is disconnected // It is triggered when the peer is disconnected
socket.on('disconnect', () => { socket.on('disconnect', () => {
console.log('peer disconnected | socket.id', socket.id); const callId = socketDetails[socket.id];
console.log(`disconnect | socket ${socket.id} | callId ${callId}`);
delete socketDetails[socket.id]; delete socketDetails[socket.id];
closeCall(callId);
}); });
/* /*
@ -187,12 +191,20 @@ peers.on('connection', async socket => {
const callId = socketDetails[socket.id]; const callId = socketDetails[socket.id];
console.log(`[createWebRtcTransport] sender ${sender} | callId ${callId}`); console.log(`[createWebRtcTransport] sender ${sender} | callId ${callId}`);
if (sender) { if (sender) {
videoCalls[callId].producerTransport = await createWebRtcTransportLayer(callId, callback); if (!videoCalls[callId].producerTransport) {
} else { videoCalls[callId].producerTransport = await createWebRtcTransportLayer(callId, callback);
videoCalls[callId].consumerTransport = await createWebRtcTransportLayer(callId, callback); } else {
console.log(`producerTransport has already been defined | callId ${callId}`);
}
} else if (!sender) {
if (!videoCalls[callId].consumerTransport) {
videoCalls[callId].consumerTransport = await createWebRtcTransportLayer(callId, callback);
} else {
console.log(`consumerTransport has already been defined | callId ${callId}`);
}
} }
} catch (error) { } catch (error) {
console.log(`ERROR | createWebRtcTransport | callId ${callId} | sender ${sender} | ${error.message}`); console.log(`ERROR | createWebRtcTransport | callId ${socketDetails[socket.id]} | sender ${sender} | ${error.message}`);
} }
}); });
@ -203,10 +215,14 @@ peers.on('connection', async socket => {
socket.on('transport-connect', async ({ dtlsParameters }) => { socket.on('transport-connect', async ({ dtlsParameters }) => {
try { try {
const callId = socketDetails[socket.id]; const callId = socketDetails[socket.id];
console.log(`[transport-connect] socket.id ${socket.id} | callId ${callId}`) // console.log('🔴 typeof dtlsParameters', typeof dtlsParameters);
// console.log('🟢 dtlsParameters', JSON.parse(dtlsParameters));
// console.log('🟡 dtlsParameters', dtlsParameters);
if (typeof dtlsParameters === 'string') dtlsParameters = JSON.parse(dtlsParameters);
console.log(`[transport-connect] socket.id ${socket.id} | callId ${callId}`);
await videoCalls[callId].producerTransport.connect({ dtlsParameters }); await videoCalls[callId].producerTransport.connect({ dtlsParameters });
} catch (error) { } catch (error) {
console.log(`ERROR | transport-connect | callId ${socketDetails[socket.id]} | ${error.message}`); console.log(`ERROR | transport-connect | callId ${socketDetails[socket.id]} | ${error.stack}`);
} }
}); });
@ -245,7 +261,7 @@ peers.on('connection', async socket => {
console.log(`[transport-recv-connect] socket.id ${socket.id} | callId ${callId}`); console.log(`[transport-recv-connect] socket.id ${socket.id} | callId ${callId}`);
await videoCalls[callId].consumerTransport.connect({ dtlsParameters }); await videoCalls[callId].consumerTransport.connect({ dtlsParameters });
} catch (error) { } catch (error) {
console.log(`ERROR | transport-recv-connect | callId ${socketDetails[socket.id]} | ERROR`); console.log(`ERROR | transport-recv-connect | callId ${socketDetails[socket.id]} | ${error.message}`);
} }
}) })
@ -302,7 +318,7 @@ peers.on('connection', async socket => {
console.log(`[canConsume] Can't consume | callId ${callId}`); console.log(`[canConsume] Can't consume | callId ${callId}`);
} }
} catch (error) { } catch (error) {
console.log(`ERROR | consume | callId ${callId} | ${error.message}`) console.log(`ERROR | consume | callId ${socketDetails[socket.id]} | ${error.message}`)
callback({ params: { error } }); callback({ params: { error } });
} }
}); });
@ -369,6 +385,7 @@ const createWebRtcTransportLayer = async (callId, callback) => {
dtlsParameters: transport.dtlsParameters, dtlsParameters: transport.dtlsParameters,
}; };
console.log(`createWebRtcTransportLayer | params.dtlsParameters ${params.dtlsParameters}`);
// Send back to the client the params // Send back to the client the params
callback({ params }); callback({ params });
@ -376,7 +393,7 @@ const createWebRtcTransportLayer = async (callId, callback) => {
return transport; return transport;
} catch (error) { } catch (error) {
console.log(`ERROR | createWebRtcTransportLayer | callId ${callId} | ${error.message}`); console.log(`ERROR | createWebRtcTransportLayer | callId ${socketDetails[socket.id]} | ${error.message}`);
callback({ params: { error } }); callback({ params: { error } });
} }
} }

BIN
doc/[video] Workflow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 KiB