From 14d96fa7c5febf5bb92231228f786d1c18eccaff Mon Sep 17 00:00:00 2001 From: Sergiu Toma Date: Tue, 2 Aug 2022 19:33:39 +0300 Subject: [PATCH] Close producer when dispatcher close the window --- app.js | 3 ++- public/index.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 05b9894..3d21d27 100644 --- a/app.js +++ b/app.js @@ -156,9 +156,10 @@ peers.on('connection', async socket => { console.log(`[transport-produce] Producer ID: ${producer.id} | kind: ${producer.kind}`) - producer.on('transportclose', () => { + producer.on('transportclose', ({ callId }) => { console.log('transport for this producer closed ') producer.close() + router[callId] = null }) // Send back to the client the Producer's id diff --git a/public/index.js b/public/index.js index c30f4d1..10cf6bd 100644 --- a/public/index.js +++ b/public/index.js @@ -56,7 +56,8 @@ if (IS_PRODUCER === true) { } if (parsedData.type === 'notify-end') { - remoteVideo.srcObject = null; + localVideo.srcObject = null + remoteVideo.srcObject = null console.log('[VIDEO] notify-end | IS_PRODUCER', IS_PRODUCER, 'callId', callId); // socket.emit('transportclose') socket.emit('transportclose') @@ -271,7 +272,7 @@ const connectSendTransport = async () => { // close video track }) - producer.on('transportclose', () => { + producer.on('transportclose', { callId },() => { console.log('transport ended') // close video track })