Compare commits

...

7 Commits

Author SHA1 Message Date
Quan HL
968fa52eac add sip decline testcase 2023-07-27 12:21:33 +07:00
Quan HL
99ad9de68e add sip decline testcase 2023-07-27 11:54:14 +07:00
Quan HL
cf8d47cb94 add sip decline testcase 2023-07-27 11:52:38 +07:00
Quan HL
2b4fc478b0 fix typo 2023-07-27 06:59:59 +07:00
Quan HL
4b800a1479 fix typo 2023-07-27 06:58:28 +07:00
Quan HL
c6af3c6a8b add testcase 2023-07-27 06:53:37 +07:00
Quan HL
b88a9d4d4d wip 2023-07-27 06:36:48 +07:00
4 changed files with 81 additions and 2 deletions

View File

@@ -796,7 +796,9 @@ class CallSession extends Emitter {
}
}
if (0 === this.tasks.length && this.requestor instanceof WsRequestor && !this.callGone) {
if (0 === this.tasks.length && ((this.requestor instanceof WsRequestor && !this.callGone) ||
// Tasks are all done, but outgoing dialog is not establish yet, waiting for cancel/handup the call.
!this.dlg && !this.isFinalStatus() && this.direction === CallDirection.Outbound)) {
//let span;
try {
//const {span} = this.rootSpan.startChildSpan('waiting for commands');
@@ -1790,6 +1792,16 @@ class CallSession extends Emitter {
//this.logger.debug(`updating redis with ${JSON.stringify(this.callInfo)}`);
this.updateCallStatus(Object.assign({}, this.callInfo.toJSON()), this.serviceUrl)
.catch((err) => this.logger.error(err, 'redis error'));
if (this.wakeupResolver && this.isFinalStatus()) {
// Someone is waiting for call to be final
this.wakeupResolver({reason: 'session ended'});
this.wakeupResolver = null;
}
}
isFinalStatus() {
return [CallStatus.Failed, CallStatus.Busy, CallStatus.NoAnswer, CallStatus.Completed].includes(this.callStatus);
}
async executeStatusCallback(callStatus, sipStatus) {

View File

@@ -32,6 +32,7 @@ test('test create-call timeout', async(t) => {
// GIVEN
let account_sid = '622f62e4-303a-49f2-bbe0-eb1e1714e37a';
const from = "restdialtimeout";
const post = bent('http://127.0.0.1:3000/', 'POST', 'json', 201);
post('v1/createCall', {
'account_sid':account_sid,
@@ -40,13 +41,22 @@ test('test create-call timeout', async(t) => {
"url": "https://public-apps.jambonz.us/hello-world",
"method": "POST"
},
"from": "15083718299",
"call_status_hook": {
"url": "http://127.0.0.1:3100/callStatus",
"method": "POST"
},
from,
"to": {
"type": "phone",
"number": "15583084809"
}});
//THEN
await p;
let obj = await getJSON(`http:127.0.0.1:3100/lastRequest/${from}_callStatus`);
t.ok(obj.body.sip_reason = 'Request Terminated',
'create-call timeout: status callback successfully executed');
disconnect();
} catch (err) {
console.log(`error received: ${err}`);

View File

@@ -15,5 +15,6 @@ require('./sip-refer-tests');
require('./listen-tests');
require('./config-test');
require('./queue-test');
require('./sip-decline-test');
require('./remove-test-db');
require('./docker_stop');

56
test/sip-decline-test.js Normal file
View File

@@ -0,0 +1,56 @@
const test = require('tape');
const { sippUac } = require('./sipp')('test_fs');
const clearModule = require('clear-module');
const {provisionCallHook} = require('./utils');
const bent = require('bent');
const getJSON = bent('json');
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});
function connect(connectable) {
return new Promise((resolve, reject) => {
connectable.on('connect', () => {
return resolve();
});
});
}
test('\'sip:decline\' tests', async(t) => {
clearModule.all();
const {srf, disconnect} = require('../app');
try {
await connect(srf);
// GIVEN
const verbs = [
{
"verb": "sip:decline",
"status": 480,
"reason": "Gone Fishing",
"headers" : {
"Retry-After": 1800
}
}
];
const from = 'sip_delecine_success';
await provisionCallHook(from, verbs)
// THEN
await sippUac('uac-invite-expect-480.xml', '172.38.0.10', from);
let obj = await getJSON(`http:127.0.0.1:3100/requests/${from}_callStatus`);
t.ok(obj.map((o) => o.body.call_status).includes('failed'),
'sip:decline: status callback successfully executed');
disconnect();
} catch (err) {
console.log(`error received: ${err}`);
disconnect();
t.error(err);
}
});