From 2c8c16195495c137ef8d95140b29777d0cc00c4d Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Mon, 3 Aug 2020 11:51:30 -0400 Subject: [PATCH] fix overlapping requests to freeswitch on outdial --- lib/tasks/gather.js | 4 ++++ lib/utils/place-outdial.js | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 772546d9..e7e00d38 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -154,6 +154,10 @@ class TaskGather extends Task { this.resolved = true; this.logger.debug(`TaskGather:resolve with reason ${reason}`); + if (this.ep && this.ep.connected) { + this.ep.stopTranscription().catch((err) => this.logger.error({err}, 'Error stopping transcription')); + } + this._clearTimer(); if (reason.startsWith('dtmf')) { await this.performAction({digits: this.digitBuffer}); diff --git a/lib/utils/place-outdial.js b/lib/utils/place-outdial.js index 610cf8e5..2891fb17 100644 --- a/lib/utils/place-outdial.js +++ b/lib/utils/place-outdial.js @@ -108,13 +108,11 @@ class SingleDialer extends Emitter { this.ep = await ms.createEndpoint(); this.logger.debug(`SingleDialer:exec - created endpoint ${this.ep.uuid}`); - let sdp; + let promiseStreamConnected; const connectStream = async(remoteSdp) => { - if (remoteSdp !== sdp) { - this.ep.modify(sdp = remoteSdp); - return true; - } - return false; + // wait for previous re-invite to complete, if any + if (promiseStreamConnected) await promiseStreamConnected.catch((err) => {}); + return promiseStreamConnected = this.ep.modify(remoteSdp); }; Object.assign(opts, { @@ -153,14 +151,17 @@ class SingleDialer extends Emitter { cbProvisional: (prov) => { const status = {sipStatus: prov.status}; if ([180, 183].includes(prov.status) && prov.body) { - status.callStatus = CallStatus.EarlyMedia; - if (connectStream(prov.body)) this.emit('earlyMedia'); + if (status.callStatus !== CallStatus.EarlyMedia) { + status.callStatus = CallStatus.EarlyMedia; + this.emit('earlyMedia'); + } + connectStream(prov.body); } else status.callStatus = CallStatus.Ringing; this.emit('callStatusChange', status); } }); - connectStream(this.dlg.remote.sdp); + await connectStream(this.dlg.remote.sdp); this.dlg.callSid = this.callSid; this.inviteInProgress = null; this.emit('callStatusChange', {sipStatus: 200, callStatus: CallStatus.InProgress});