From 42dffe1cbb019ff434d9aafb6ae35f8cdb521253 Mon Sep 17 00:00:00 2001 From: Sergiu Toma Date: Mon, 5 Sep 2022 18:11:13 +0300 Subject: [PATCH] Send answer and connect to transport layer created with 7s delay --- public/index.js | 97 +++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 60 deletions(-) diff --git a/public/index.js b/public/index.js index d2bb032..055d5aa 100644 --- a/public/index.js +++ b/public/index.js @@ -208,24 +208,6 @@ const getRtpCapabilities = () => { const createSendTransport = () => { - setTimeout(() => { - const answer = { - origin_asset_id: ASSET_ID, - dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')), - type: 'notify-answer', - origin_asset_priority: 1, - origin_asset_type_name: ASSET_TYPE, - origin_asset_name: ASSET_NAME, - video_call_id: callId, - answer: 'accepted', // answer: 'rejected' - }; - console.log('SEND answer', answer); - hub.emit( - 'video', - JSON.stringify(answer) - ); - - // see server's socket.on('createWebRtcTransport', sender?, ...) // this is a call from Producer, so sender = true socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => { @@ -287,52 +269,47 @@ const createSendTransport = () => { }) connectSendTransport() }) - - - - }, 7000); } const connectSendTransport = async () => { - console.log('[connectSendTransport]'); - // we now call produce() to instruct the producer transport - // to send media to the Router - // https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce - // this action will trigger the 'connect' and 'produce' events above - producer = await producerTransport.produce(params) + setTimeout(() => { + console.log('[connectSendTransport]'); + // we now call produce() to instruct the producer transport + // to send media to the Router + // https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce + // this action will trigger the 'connect' and 'produce' events above + producer = await producerTransport.produce(params) + + producer.on('trackended', () => { + console.log('track ended') + // close video track + }) + + producer.on('transportclose', () => { + console.log('transport ended') + // close video track + }) + + // Enable Close call button + const closeCallBtn = document.getElementById('btnCloseCall'); + closeCallBtn.removeAttribute('disabled'); - producer.on('trackended', () => { - console.log('track ended') - // close video track - }) - - producer.on('transportclose', () => { - console.log('transport ended') - // close video track - }) - - const answer = { - origin_asset_id: ASSET_ID, - dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')), - type: 'notify-answer', - origin_asset_priority: 1, - origin_asset_type_name: ASSET_TYPE, - origin_asset_name: ASSET_NAME, - video_call_id: callId, - answer: 'accepted', // answer: 'rejected' - }; - console.log('SEND answer', answer); - - // setTimeout(() => { - // hub.emit( - // 'video', - // JSON.stringify(answer) - // ); - // }, 7000); - - // Enable Close call button - const closeCallBtn = document.getElementById('btnCloseCall'); - closeCallBtn.removeAttribute('disabled'); + const answer = { + origin_asset_id: ASSET_ID, + dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')), + type: 'notify-answer', + origin_asset_priority: 1, + origin_asset_type_name: ASSET_TYPE, + origin_asset_name: ASSET_NAME, + video_call_id: callId, + answer: 'accepted', // answer: 'rejected' + }; + console.log('SEND answer', answer); + hub.emit( + 'video', + JSON.stringify(answer) + ); + }, 7000); } const createRecvTransport = async () => {