From 33ea44ac02de38a563df605feadb6b1b38549369 Mon Sep 17 00:00:00 2001 From: Sergiu Toma Date: Sat, 11 Feb 2023 21:30:21 +0200 Subject: [PATCH] Update client to consume audio correctly --- public/bundle.js | 55 +++++++++++++++++++++++++----------------------- public/index.js | 55 +++++++++++++++++++++++++----------------------- 2 files changed, 58 insertions(+), 52 deletions(-) diff --git a/public/bundle.js b/public/bundle.js index aa7ab9f..e7f4484 100644 --- a/public/bundle.js +++ b/public/bundle.js @@ -20453,9 +20453,9 @@ setTimeout(() => { if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() } }) - socket.on('new-producer', ({ callId }) => { - console.log(`🟢 new-producer | callId: ${callId} | Ready to consume`); - consume() + socket.on('new-producer', ({ callId, kind }) => { + console.log(`🟢 new-producer | callId: ${callId} | kind: ${kind} | Ready to consume`); + connectRecvTransport(); }) } @@ -20735,6 +20735,8 @@ const connectSendTransport = async () => { // Enable Close call button const closeCallBtn = document.getElementById('btnCloseCall'); closeCallBtn.removeAttribute('disabled'); + + createRecvTransport(); } const createRecvTransport = async () => { @@ -20774,7 +20776,8 @@ const createRecvTransport = async () => { errback(error) } }) - connectRecvTransport() + // We call it in new-rpoducer, we don't need it here anymore + // connectRecvTransport() }) } @@ -20907,29 +20910,29 @@ const closeCall = () => { resetCallSettings() } -const consume = async () => { - console.log('[consume]') - console.log('createRecvTransport Consumer') - await socket.emit('createWebRtcTransport', { sender: false, callId, dispatcher: true }, ({ params }) => { - if (params.error) { - console.log('createRecvTransport | createWebRtcTransport | Error', params.error) - return - } - consumerTransport = device.createRecvTransport(params) - consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => { - try { - await socket.emit('transport-recv-connect', { - dtlsParameters, - }) - callback() - } catch (error) { - errback(error) - } - }) +// const consume = async (kind) => { +// console.log(`[consume] kind: ${kind}`) +// console.log('createRecvTransport Consumer') +// await socket.emit('createWebRtcTransport', { sender: false, callId, dispatcher: true }, ({ params }) => { +// if (params.error) { +// console.log('createRecvTransport | createWebRtcTransport | Error', params.error) +// return +// } +// consumerTransport = device.createRecvTransport(params) +// consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => { +// try { +// await socket.emit('transport-recv-connect', { +// dtlsParameters, +// }) +// callback() +// } catch (error) { +// errback(error) +// } +// }) - connectRecvTransport() - }) -} +// connectRecvTransport() +// }) +// } btnLocalVideo.addEventListener('click', getLocalStream) btnRecvSendTransport.addEventListener('click', consume) diff --git a/public/index.js b/public/index.js index 1fbf13a..ddb2c0b 100644 --- a/public/index.js +++ b/public/index.js @@ -95,9 +95,9 @@ setTimeout(() => { if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() } }) - socket.on('new-producer', ({ callId }) => { - console.log(`🟢 new-producer | callId: ${callId} | Ready to consume`); - consume() + socket.on('new-producer', ({ callId, kind }) => { + console.log(`🟢 new-producer | callId: ${callId} | kind: ${kind} | Ready to consume`); + connectRecvTransport(); }) } @@ -377,6 +377,8 @@ const connectSendTransport = async () => { // Enable Close call button const closeCallBtn = document.getElementById('btnCloseCall'); closeCallBtn.removeAttribute('disabled'); + + createRecvTransport(); } const createRecvTransport = async () => { @@ -416,7 +418,8 @@ const createRecvTransport = async () => { errback(error) } }) - connectRecvTransport() + // We call it in new-rpoducer, we don't need it here anymore + // connectRecvTransport() }) } @@ -549,29 +552,29 @@ const closeCall = () => { resetCallSettings() } -const consume = async () => { - console.log('[consume]') - console.log('createRecvTransport Consumer') - await socket.emit('createWebRtcTransport', { sender: false, callId, dispatcher: true }, ({ params }) => { - if (params.error) { - console.log('createRecvTransport | createWebRtcTransport | Error', params.error) - return - } - consumerTransport = device.createRecvTransport(params) - consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => { - try { - await socket.emit('transport-recv-connect', { - dtlsParameters, - }) - callback() - } catch (error) { - errback(error) - } - }) +// const consume = async (kind) => { +// console.log(`[consume] kind: ${kind}`) +// console.log('createRecvTransport Consumer') +// await socket.emit('createWebRtcTransport', { sender: false, callId, dispatcher: true }, ({ params }) => { +// if (params.error) { +// console.log('createRecvTransport | createWebRtcTransport | Error', params.error) +// return +// } +// consumerTransport = device.createRecvTransport(params) +// consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => { +// try { +// await socket.emit('transport-recv-connect', { +// dtlsParameters, +// }) +// callback() +// } catch (error) { +// errback(error) +// } +// }) - connectRecvTransport() - }) -} +// connectRecvTransport() +// }) +// } btnLocalVideo.addEventListener('click', getLocalStream) btnRecvSendTransport.addEventListener('click', consume)