From 24390c98e54d1c3b1978ee7ad4f18b78acb15f4b Mon Sep 17 00:00:00 2001 From: Sergiu Toma Date: Mon, 24 Oct 2022 22:11:14 +0300 Subject: [PATCH 1/5] LH-259: Added callbacks --- app.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app.js b/app.js index f1ca550..bad26fe 100644 --- a/app.js +++ b/app.js @@ -124,16 +124,6 @@ const closeCall = (callId) => { } } -const getRtpCapabilities = (callId, callback) => { - try { - console.log('[getRtpCapabilities] callId', callId); - const rtpCapabilities = videoCalls[callId].router.rtpCapabilities; - callback({ rtpCapabilities }); - } catch (error) { - console.log(`ERROR | getRtpCapabilities | callId ${callId} | ${error.message}`); - } -} - /* - Handlers for WS events - These are created only when we have a connection with a peer @@ -160,7 +150,9 @@ peers.on('connection', async socket => { - If the room already exists, it will not create it, but will only return rtpCapabilities */ socket.on('createRoom', async ({ callId }, callback) => { + let callbackResponse = null; try { + // We can continue with the room creation process only if we have a callId if (callId) { console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`); if (!videoCalls[callId]) { @@ -169,12 +161,17 @@ peers.on('connection', async socket => { console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`); } socketDetails[socket.id] = callId; - getRtpCapabilities(callId, callback); + + // rtpCapabilities is set for callback + console.log('[getRtpCapabilities] callId', callId); + callbackResponse = videoCalls[callId].router.rtpCapabilities; } else { console.log(`[createRoom] missing callId ${callId}`); } } catch (error) { console.log(`ERROR | createRoom | callId ${callId} | ${error.message}`); + } finally { + callback(callbackResponse); } }); @@ -195,16 +192,19 @@ peers.on('connection', async socket => { 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].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}`); + callback(error); } }); @@ -248,9 +248,9 @@ peers.on('connection', async socket => { }); // Send back to the client the Producer's id - // callback({ - // id: videoCalls[callId].producer.id - // }); + callback({ + id: videoCalls[callId].producer.id + }); } catch (error) { console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`); } @@ -321,6 +321,7 @@ peers.on('connection', async socket => { callback({ params }); } else { console.log(`[canConsume] Can't consume | callId ${callId}`); + callback(null); } } catch (error) { console.log(`ERROR | consume | callId ${socketDetails[socket.id]} | ${error.message}`) -- 2.37.1 From 9f8347bec52c8fa47eb10a5db8f9e7557e70f1ca Mon Sep 17 00:00:00 2001 From: Sergiu Toma Date: Mon, 24 Oct 2022 22:16:47 +0300 Subject: [PATCH 2/5] LH-259: Update createRoom callback --- app.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index bad26fe..4b73ec5 100644 --- a/app.js +++ b/app.js @@ -164,7 +164,10 @@ peers.on('connection', async socket => { // rtpCapabilities is set for callback console.log('[getRtpCapabilities] callId', callId); - callbackResponse = videoCalls[callId].router.rtpCapabilities; + callbackResponse = { + rtpCapabilities :videoCalls[callId].router.rtpCapabilities + }; + callback(callbackResponse); } else { console.log(`[createRoom] missing callId ${callId}`); } -- 2.37.1 From b59a157b18c9ab7024a73f69183c43afac9a3b2c Mon Sep 17 00:00:00 2001 From: Sergiu Toma Date: Mon, 24 Oct 2022 22:19:37 +0300 Subject: [PATCH 3/5] LH-259: Comment callback from transport-produce --- app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 4b73ec5..190d30b 100644 --- a/app.js +++ b/app.js @@ -251,9 +251,9 @@ peers.on('connection', async socket => { }); // Send back to the client the Producer's id - callback({ - id: videoCalls[callId].producer.id - }); + // callback({ + // id: videoCalls[callId].producer.id + // }); } catch (error) { console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`); } -- 2.37.1 From f4ebf92783295fb14e9b6c190fe5ba0b25f5503f Mon Sep 17 00:00:00 2001 From: Sergiu Toma Date: Mon, 24 Oct 2022 22:35:22 +0300 Subject: [PATCH 4/5] LH-259: Added callback from transport-produce --- app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 190d30b..ab4b57b 100644 --- a/app.js +++ b/app.js @@ -251,9 +251,9 @@ peers.on('connection', async socket => { }); // Send back to the client the Producer's id - // callback({ - // id: videoCalls[callId].producer.id - // }); + callback && callback({ + id: videoCalls[callId].producer.id + }); } catch (error) { console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`); } -- 2.37.1 From 084ff36ebed6fceadb79f9deb6d0a1dd5a65f7cd Mon Sep 17 00:00:00 2001 From: Sergiu Toma Date: Mon, 24 Oct 2022 22:38:06 +0300 Subject: [PATCH 5/5] LH-259: Refactor createRoom --- app.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app.js b/app.js index ab4b57b..702eb14 100644 --- a/app.js +++ b/app.js @@ -167,7 +167,6 @@ peers.on('connection', async socket => { callbackResponse = { rtpCapabilities :videoCalls[callId].router.rtpCapabilities }; - callback(callbackResponse); } else { console.log(`[createRoom] missing callId ${callId}`); } -- 2.37.1