mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
added support for sip:request verb, used to send SIP INFO/NOTIFY etc during call (#116)
This commit is contained in:
@@ -17,6 +17,9 @@ function makeTask(logger, obj, parent) {
|
||||
case TaskName.SipDecline:
|
||||
const TaskSipDecline = require('./sip_decline');
|
||||
return new TaskSipDecline(logger, data, parent);
|
||||
case TaskName.SipRequest:
|
||||
const TaskSipRequest = require('./sip_request');
|
||||
return new TaskSipRequest(logger, data, parent);
|
||||
case TaskName.SipRefer:
|
||||
const TaskSipRefer = require('./sip_refer');
|
||||
return new TaskSipRefer(logger, data, parent);
|
||||
|
||||
48
lib/tasks/sip_request.js
Normal file
48
lib/tasks/sip_request.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const Task = require('./task');
|
||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||
|
||||
/**
|
||||
* Send a SIP request (e.g. INFO, NOTIFY, etc) on an existing call leg
|
||||
*/
|
||||
class TaskSipRequest extends Task {
|
||||
constructor(logger, opts) {
|
||||
super(logger, opts);
|
||||
this.preconditions = TaskPreconditions.StableCall;
|
||||
|
||||
this.method = this.data.method.toUpperCase();
|
||||
this.headers = this.data.headers || {};
|
||||
this.body = this.data.body;
|
||||
}
|
||||
|
||||
get name() { return TaskName.SipRequest; }
|
||||
|
||||
async exec(cs, dlg) {
|
||||
super.exec(cs);
|
||||
try {
|
||||
this.logger.info({dlg}, `TaskSipRequest: sending a SIP ${this.method}`);
|
||||
const res = await dlg.request({
|
||||
method: this.method,
|
||||
headers: this.headers,
|
||||
body: this.body
|
||||
});
|
||||
const result = {result: 'success', sipStatus: res.status};
|
||||
this.span.setAttributes({
|
||||
...this.headers,
|
||||
...(this.body && {body: this.body}),
|
||||
'response.status_code': res.status
|
||||
});
|
||||
this.logger.debug({result}, `TaskSipRequest: received response to ${this.method}`);
|
||||
await this.performAction(result);
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'TaskSipRequest: error');
|
||||
this.span.setAttributes({
|
||||
...this.headers,
|
||||
...(this.body && {body: this.body}),
|
||||
'response.error': err.message
|
||||
});
|
||||
await this.performAction({result: 'failed', err: err.message});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TaskSipRequest;
|
||||
@@ -9,6 +9,17 @@
|
||||
"status"
|
||||
]
|
||||
},
|
||||
"sip:request": {
|
||||
"properties": {
|
||||
"method": "string",
|
||||
"body": "string",
|
||||
"headers": "object",
|
||||
"actionHook": "object|string"
|
||||
},
|
||||
"required": [
|
||||
"method"
|
||||
]
|
||||
},
|
||||
"sip:refer": {
|
||||
"properties": {
|
||||
"referTo": "string",
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"Redirect": "redirect",
|
||||
"RestDial": "rest:dial",
|
||||
"SipDecline": "sip:decline",
|
||||
"SipRequest": "sip:request",
|
||||
"SipRefer": "sip:refer",
|
||||
"SipNotify": "sip:notify",
|
||||
"SipRedirect": "sip:redirect",
|
||||
|
||||
Reference in New Issue
Block a user