mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
Feature/incoming refer (#76)
* Dial: handle incoming REFER on either leg by calling referHook, if configured * lint * modify payload of referHook * support target.trunk on rest createCall api * bugfix: gather partial result hook was not working * lint * handling of incoming REFER
This commit is contained in:
@@ -521,6 +521,29 @@ class CallSession extends Emitter {
|
||||
task.doConferenceMuteNonModerators(this, opts);
|
||||
}
|
||||
|
||||
async _lccSipRequest(callSid, opts) {
|
||||
const {sip_request} = opts;
|
||||
const {method, content_type, content, headers = {}} = sip_request;
|
||||
if (!this.hasStableDialog) {
|
||||
this.logger.info('CallSession:_lccSipRequest - invalid command as we do not have a stable call');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await this.dlg.request({
|
||||
method,
|
||||
headers: {
|
||||
...headers,
|
||||
'Content-Type': content_type,
|
||||
'Content': content
|
||||
}
|
||||
});
|
||||
this.logger.debug({res}, `CallSession:_lccSipRequest got response to ${method}`);
|
||||
return res;
|
||||
} catch (err) {
|
||||
this.logger.error({err}, `CallSession:_lccSipRequest - error sending ${method}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* perform live call control -- whisper to one party or the other on a call
|
||||
* @param {array} opts - array of play or say tasks
|
||||
@@ -596,6 +619,10 @@ class CallSession extends Emitter {
|
||||
else if (opts.conf_mute_status) {
|
||||
await this._lccConfMuteStatus(callSid, opts);
|
||||
}
|
||||
else if (opts.sip_request) {
|
||||
const res = await this._lccSipRequest(callSid, opts);
|
||||
return {status: res.status, reason: res.reason};
|
||||
}
|
||||
|
||||
// whisper may be the only thing we are asked to do, or it may that
|
||||
// we are doing a whisper after having muted, paused reccording etc..
|
||||
@@ -752,7 +779,11 @@ class CallSession extends Emitter {
|
||||
} catch (err) {
|
||||
if (err === CALLER_CANCELLED_ERR_MSG) {
|
||||
this.logger.error(err, 'caller canceled quickly before we could respond, ending call');
|
||||
this._notifyCallStatusChange({callStatus: CallStatus.NoAnswer, sipStatus: 487});
|
||||
this._notifyCallStatusChange({
|
||||
callStatus: CallStatus.NoAnswer,
|
||||
sipStatus: 487,
|
||||
sipReason: 'Request Terminated'
|
||||
});
|
||||
this._callReleased();
|
||||
}
|
||||
else {
|
||||
@@ -862,9 +893,10 @@ class CallSession extends Emitter {
|
||||
this.dlg.on('destroy', this._callerHungup.bind(this));
|
||||
this.wrapDialog(this.dlg);
|
||||
this.dlg.callSid = this.callSid;
|
||||
this.emit('callStatusChange', {sipStatus: 200, callStatus: CallStatus.InProgress});
|
||||
this.emit('callStatusChange', {sipStatus: 200, sipReason: 'OK', callStatus: CallStatus.InProgress});
|
||||
|
||||
this.dlg.on('modify', this._onReinvite.bind(this));
|
||||
this.dlg.on('refer', this._onRefer.bind(this));
|
||||
|
||||
this.logger.debug(`CallSession:propagateAnswer - answered callSid ${this.callSid}`);
|
||||
}
|
||||
@@ -890,6 +922,22 @@ class CallSession extends Emitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming REFER if we are in a dial task
|
||||
* @param {*} req
|
||||
* @param {*} res
|
||||
*/
|
||||
_onRefer(req, res) {
|
||||
const task = this.currentTask;
|
||||
const sd = task.sd;
|
||||
if (task && TaskName.Dial === task.name && sd) {
|
||||
task.handleRefer(this, req, res);
|
||||
}
|
||||
else {
|
||||
res.send(501);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create and endpoint if we don't have one; otherwise simply return
|
||||
* the current media server and endpoint that are associated with this call
|
||||
@@ -1075,7 +1123,7 @@ class CallSession extends Emitter {
|
||||
* @param {number} sipStatus - current sip status
|
||||
* @param {number} [duration] - duration of a completed call, in seconds
|
||||
*/
|
||||
_notifyCallStatusChange({callStatus, sipStatus, duration}) {
|
||||
_notifyCallStatusChange({callStatus, sipStatus, sipReason, duration}) {
|
||||
if (this.callMoved) return;
|
||||
|
||||
/* race condition: we hang up at the same time as the caller */
|
||||
@@ -1088,7 +1136,7 @@ class CallSession extends Emitter {
|
||||
(!duration && callStatus !== CallStatus.Completed),
|
||||
'duration MUST be supplied when call completed AND ONLY when call completed');
|
||||
|
||||
this.callInfo.updateCallStatus(callStatus, sipStatus);
|
||||
this.callInfo.updateCallStatus(callStatus, sipStatus, sipReason);
|
||||
if (typeof duration === 'number') this.callInfo.duration = duration;
|
||||
try {
|
||||
this.notifier.request('call:status', this.call_status_hook, this.callInfo.toJSON());
|
||||
|
||||
Reference in New Issue
Block a user