Feat/handle 3pcc invite (#1005)

* wip

* wip

* linting
This commit is contained in:
Dave Horton
2024-12-12 18:39:15 -05:00
committed by GitHub
parent c29ab0d858
commit 0aa37a83ae

View File

@@ -400,6 +400,13 @@ class CallSession extends Emitter {
return this.application.transferredCall === true; return this.application.transferredCall === true;
} }
/**
* returns true if this session is an inbound call session
*/
get isInboundCallSession() {
return this.constructor.name === 'InboundCallSession';
}
/** /**
* returns true if this session is a ConfirmCallSession * returns true if this session is a ConfirmCallSession
*/ */
@@ -428,6 +435,10 @@ class CallSession extends Emitter {
return this.constructor.name === 'SmsCallSession'; return this.constructor.name === 'SmsCallSession';
} }
get is3pccInvite() {
return this.isInboundCallSession && this.req?.body?.length === 0;
}
get webhook_secret() { get webhook_secret() {
return this.accountInfo?.account?.webhook_secret; return this.accountInfo?.account?.webhook_secret;
} }
@@ -2098,7 +2109,6 @@ Duration=${duration} `
//ep.cs = this; //ep.cs = this;
this.ep = ep; this.ep = ep;
this.logger.info(`allocated endpoint ${ep.uuid}`); this.logger.info(`allocated endpoint ${ep.uuid}`);
this._configMsEndpoint(); this._configMsEndpoint();
this.ep.on('destroy', () => { this.ep.on('destroy', () => {
@@ -2260,22 +2270,43 @@ Duration=${duration} `
}, },
localSdp: this.ep.local.sdp localSdp: this.ep.local.sdp
}); });
this.logger.debug('answered call');
this.dlg.on('destroy', this._callerHungup.bind(this));
this.wrapDialog(this.dlg);
this.dlg.callSid = this.callSid;
this.emit('callStatusChange', {sipStatus: 200, sipReason: 'OK', callStatus: CallStatus.InProgress});
if (this.recordOptions && this.recordState === RecordState.RecordingOff) { const tidyUp = () => {
this.startRecording(); this.dlg.on('destroy', this._callerHungup.bind(this));
this.wrapDialog(this.dlg);
this.dlg.callSid = this.callSid;
this.emit('callStatusChange', {sipStatus: 200, sipReason: 'OK', callStatus: CallStatus.InProgress});
if (this.recordOptions && this.recordState === RecordState.RecordingOff) {
this.startRecording();
}
this.dlg.on('modify', this._onReinvite.bind(this));
this.dlg.on('refer', this._onRefer.bind(this));
if (this.sipRequestWithinDialogHook) {
this.dlg.on('info', this._onRequestWithinDialog.bind(this));
this.dlg.on('message', this._onRequestWithinDialog.bind(this));
}
this.logger.debug(`CallSession:propagateAnswer - answered callSid ${this.callSid}`);
};
if (this.is3pccInvite) {
return new Promise((resolve, reject) => {
this.dlg.once('ack', (ackRequest) => {
this.logger.debug({body: ackRequest.body}, 'received ACK for 3pcc invite');
this.ep.modify(ackRequest.body)
.then(() => {
tidyUp();
return resolve();
})
.catch((err) => {
this.logger.info({err}, 'Error modifying endpoint with ACK');
reject(err);
});
});
this.logger.debug('this is a 3pcc invite');
});
} }
this.dlg.on('modify', this._onReinvite.bind(this)); tidyUp();
this.dlg.on('refer', this._onRefer.bind(this));
if (this.sipRequestWithinDialogHook) {
this.dlg.on('info', this._onRequestWithinDialog.bind(this));
this.dlg.on('message', this._onRequestWithinDialog.bind(this));
}
this.logger.debug(`CallSession:propagateAnswer - answered callSid ${this.callSid}`);
} }
else { else {
this.logger.debug('CallSession:propagateAnswer - call already answered - re-anchor media with a reinvite'); this.logger.debug('CallSession:propagateAnswer - call already answered - re-anchor media with a reinvite');