mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
refactor answer code into one location
This commit is contained in:
@@ -443,7 +443,7 @@ class CallSession extends Emitter {
|
|||||||
if (!task.earlyMedia || this.dlg) return this.ep;
|
if (!task.earlyMedia || this.dlg) return this.ep;
|
||||||
|
|
||||||
// we are going from an early media connection to answer
|
// we are going from an early media connection to answer
|
||||||
await answerCall();
|
await this.propagateAnswer();
|
||||||
return this.ep;
|
return this.ep;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,7 +459,7 @@ class CallSession extends Emitter {
|
|||||||
this.res.send(183, {body: ep.local.sdp});
|
this.res.send(183, {body: ep.local.sdp});
|
||||||
return ep;
|
return ep;
|
||||||
}
|
}
|
||||||
answerCall();
|
this.propagateAnswer();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// outbound call TODO
|
// outbound call TODO
|
||||||
@@ -541,6 +541,36 @@ class CallSession extends Emitter {
|
|||||||
return this.ms;
|
return this.ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Answer the call, if it has not already been answered.
|
||||||
|
*
|
||||||
|
* NB: This should be the one and only place we generate 200 OK to incoming INVITEs
|
||||||
|
*/
|
||||||
|
async propagateAnswer() {
|
||||||
|
if (!this.dlg) {
|
||||||
|
assert(this.ep);
|
||||||
|
this.dlg = await this.srf.createUAS(this.req, this.res, {localSdp: this.ep.local.sdp});
|
||||||
|
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.dlg.on('modify', this._onReinvite.bind(this));
|
||||||
|
|
||||||
|
this.logger.debug(`CallSession:propagateAnswer - answered callSid ${this.callSid}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async _onReinvite(req, res) {
|
||||||
|
try {
|
||||||
|
const newSdp = await this.ep.modify(req.body);
|
||||||
|
res.send(200, {body: newSdp});
|
||||||
|
this.logger.info({offer: req.body, answer: newSdp}, 'handling reINVITE');
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error(err, 'Error handling reinvite');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create and endpoint if we don't have one; otherwise simply return
|
* create and endpoint if we don't have one; otherwise simply return
|
||||||
* the current media server and endpoint that are associated with this call
|
* the current media server and endpoint that are associated with this call
|
||||||
|
|||||||
@@ -43,20 +43,6 @@ class InboundCallSession extends CallSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Answer the call, if it has not already been answered.
|
|
||||||
*/
|
|
||||||
async propagateAnswer() {
|
|
||||||
if (!this.dlg) {
|
|
||||||
assert(this.ep);
|
|
||||||
this.dlg = await this.srf.createUAS(this.req, this.res, {localSdp: this.ep.local.sdp});
|
|
||||||
this.wrapDialog(this.dlg);
|
|
||||||
this.dlg.on('destroy', this._callerHungup.bind(this));
|
|
||||||
this.emit('callStatusChange', {sipStatus: 200, callStatus: CallStatus.InProgress});
|
|
||||||
this.logger.debug(`CallSession:propagateAnswer - answered callSid ${this.callSid}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is invoked when the caller hangs up, in order to calculate the call duration.
|
* This is invoked when the caller hangs up, in order to calculate the call duration.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user