more testing

This commit is contained in:
Dave Horton
2020-01-25 15:51:47 -05:00
parent 12d49a40a4
commit 0df1e44f15
9 changed files with 79 additions and 49 deletions

View File

@@ -15,7 +15,7 @@ function compareTasks(t1, t2) {
case 'user':
return t2.name === t1.name;
case 'sip':
return t2.uri === t1.uri;
return t2.sipUri === t1.sipUri;
}
}
@@ -50,12 +50,11 @@ class TaskDial extends Task {
this.dialMusic = this.data.dialMusic;
this.headers = this.data.headers || {};
this.method = this.data.method || 'POST';
this.statusCallback = this.data.statusCallback;
this.statusCallbackMethod = this.data.statusCallbackMethod || 'POST';
this.target = filterAndLimit(this.logger, this.data.target);
this.timeout = this.data.timeout || 60;
this.timeLimit = this.data.timeLimit;
this.url = this.data.url;
this.confirmUrl = this.data.confirmUrl;
this.confirmMethod = this.data.confirmMethod;
if (this.data.listen) {
this.listenTask = makeTask(logger, {'listen': this.data.listen});
@@ -79,7 +78,7 @@ class TaskDial extends Task {
}
await this._attemptCalls(cs);
await this.awaitTaskDone();
this.performAction(this.method, null, this.results);
await this.performAction(this.method, null, this.results);
} catch (err) {
this.logger.error(`TaskDial:exec terminating with error ${err.message}`);
this.kill();
@@ -88,21 +87,21 @@ class TaskDial extends Task {
async kill() {
super.kill();
if (this.connectTime) {
const duration = moment().diff(this.connectTime, 'seconds');
if (this.dlg) {
const duration = moment().diff(this.dlg.connectTime, 'seconds');
this.results.dialCallDuration = duration;
this.logger.debug(`Dial:kill call ended after ${duration} seconds`);
}
this._killOutdials();
if (this.listenTask) await this.listenTask.kill();
if (this.transcribeTask) await this.transcribeTask.kill();
if (this.dlg) {
assert(this.ep);
if (this.dlg.connected) this.dlg.destroy();
debug(`Dial:kill deleting endpoint ${this.ep.uuid}`);
this.ep.destroy();
}
if (this.listenTask) await this.listenTask.kill();
if (this.transcribeTask) await this.transcribeTask.kill();
this.notifyTaskDone();
}
@@ -126,7 +125,7 @@ class TaskDial extends Task {
`${req.source_address}:${req.source_port}` :
config.get('sbcAddress');
const opts = {
headers: this.headers,
headers: req && req.has('X-CID') ? Object.assign(this.headers, {'X-CID': req.get('X-CID')}) : this.headers,
proxy: `sip:${sbcAddress}`,
callingNumber: this.callerId || req.callingNumber
};
@@ -138,9 +137,15 @@ class TaskDial extends Task {
['callSid', 'callID', 'from', 'to', 'callerId', 'sipStatus', 'callStatus'].forEach((k) => delete callInfo[k]);
const ms = await cs.getMS();
const timerRing = setTimeout(() => {
this.logger.info(`Dial:_attemptCall: ring no answer timer ${this.timeout}s exceeded`);
this._killOutdials();
}, this.timeout * 1000);
this.target.forEach((t) => {
try {
t.url = t.url || this.url;
t.url = t.url || this.confirmUrl;
t.method = t.method || this.confirmMethod;
const sd = placeCall({
logger: this.logger,
application: cs.application,
@@ -165,13 +170,15 @@ class TaskDial extends Task {
break;
case CallStatus.InProgress:
this.logger.debug('Dial:_attemptCall -- call was answered');
clearTimeout(timerRing);
break;
case CallStatus.Failed:
case CallStatus.Busy:
case CallStatus.NoAnswer:
this.dials.delete(sd.callSid);
if (this.dials.size === 0 && !this.connectTime) {
if (this.dials.size === 0 && !this.dlg) {
this.logger.debug('Dial:_attemptCalls - all calls failed after call failure, ending task');
clearTimeout(timerRing);
this.kill();
}
break;
@@ -190,7 +197,7 @@ class TaskDial extends Task {
.on('decline', () => {
this.logger.debug(`Dial:_attemptCalls - declined: ${sd.callSid}`);
this.dials.delete(sd.callSid);
if (this.dials.size === 0 && !this.connectTime) {
if (this.dials.size === 0 && !this.dlg) {
this.logger.debug('Dial:_attemptCalls - all calls failed after decline, ending task');
this.kill();
}
@@ -214,19 +221,38 @@ class TaskDial extends Task {
this._killOutdials(); // NB: order is important
}
/**
* We now have a call leg produced by the Dial action, so
* - hangup any simrings in progress
* - save the dialog and endpoint
* - clock the start time of the call,
* - start a max call length timer (optionally)
* - launch any nested tasks
* - and establish a handler to clean up if the called party hangs up
*/
_selectSingleDial(cs, sd) {
this.connectTime = moment();
this.dials.delete(sd.callSid);
debug(`Dial:_selectSingleDial ep for outbound call: ${sd.ep.uuid}`);
this.dials.delete(sd.callSid);
this.ep = sd.ep;
this.dlg = sd.dlg;
this.dlg.connectTime = moment();
this.callSid = sd.callSid;
if (this.earlyMedia) {
debug('Dial:_selectSingleDial propagating answer supervision on A leg now that B is connected');
cs.propagateAnswer();
}
let timerMaxCallDuration;
if (this.timeLimit) {
timerMaxCallDuration = setTimeout(() => {
this.logger.info(`Dial:_selectSingleDial tearing down call as it has reached ${this.timeLimit}s`);
this.ep.unbridge();
this.kill();
}, this.timeLimit * 1000);
}
this.dlg.on('destroy', () => {
this.logger.debug('Dial:_selectSingleDial called party hungup, ending dial operation');
if (timerMaxCallDuration) clearTimeout(timerMaxCallDuration);
this.ep.unbridge();
this.kill();
});