diff --git a/lib/http-routes/api/create-call.js b/lib/http-routes/api/create-call.js index 7567bab2..0419975e 100644 --- a/lib/http-routes/api/create-call.js +++ b/lib/http-routes/api/create-call.js @@ -134,9 +134,6 @@ router.post('/', async(req, res) => { if (req.body.dual_streams) { dualEp = await ms.createEndpoint(); localSdp = mergeSdpMedia(localSdp, dualEp.local.sdp); - ep.on('destroy', () => { - dualEp.destroy(); - }); } const connectStream = async(remoteSdp) => { @@ -145,7 +142,8 @@ router.post('/', async(req, res) => { if (req.body.dual_streams) { const [sdpLegA, sdpLebB] = extractSdpMedia(remoteSdp); - await Promise.all([ep.modify(sdpLegA), dualEp.modify(sdpLebB)]); + await ep.modify(sdpLegA); + await dualEp.modify(sdpLebB); await ep.bridge(dualEp); } else { ep.modify(sdp); @@ -243,6 +241,7 @@ router.post('/', async(req, res) => { srf, req: inviteReq, ep, + ep2: dualEp, tasks, callInfo, accountInfo, @@ -295,6 +294,9 @@ router.post('/', async(req, res) => { else console.error(err); } ep.destroy(); + if (dualEp) { + dualEp.destroy(); + } setTimeout(restDial.kill.bind(restDial, cs), 5000); } } catch (err) { diff --git a/lib/session/rest-call-session.js b/lib/session/rest-call-session.js index 08950f22..73384c2b 100644 --- a/lib/session/rest-call-session.js +++ b/lib/session/rest-call-session.js @@ -8,7 +8,7 @@ const moment = require('moment'); * @extends CallSession */ class RestCallSession extends CallSession { - constructor({logger, application, srf, req, ep, tasks, callInfo, accountInfo, rootSpan}) { + constructor({logger, application, srf, req, ep, ep2, tasks, callInfo, accountInfo, rootSpan}) { super({ logger, application, @@ -21,6 +21,7 @@ class RestCallSession extends CallSession { }); this.req = req; this.ep = ep; + this.ep2 = ep2; // keep restDialTask reference for closing AMD if (tasks.length) { this.restDialTask = tasks[0];