initial WIP to remove freeswitch from media path when not recording or transcribing dial calls

This commit is contained in:
Dave Horton
2021-10-08 16:21:47 -04:00
parent bedf25c6a2
commit 9f158a8cf7
4 changed files with 55 additions and 8 deletions

View File

@@ -130,6 +130,8 @@ class TaskDial extends Task {
get name() { return TaskName.Dial; }
get canReleaseMedia() { return !this.dtmfHook && !this.listenTask && !this.transcribeTask; }
async exec(cs) {
await super.exec(cs);
try {
@@ -255,7 +257,8 @@ class TaskDial extends Task {
debug(`Dial:__initializeInbound allocated ep for incoming call: ${ep.uuid}`);
/* send outbound legs back to the same SBC (to support static IP feature) */
if (!this.proxy) this.proxy = `${cs.req.source_address}:${cs.req.source_port};transport=tcp`;
//if (!this.proxy) this.proxy = `${cs.req.source_address}:${cs.req.source_port};transport=tcp`;
if (!this.proxy) this.proxy = `${cs.req.source_address}:${cs.req.source_port}`;
if (this.dialMusic) {
// play dial music to caller while we outdial
@@ -395,7 +398,7 @@ class TaskDial extends Task {
}
_connectSingleDial(cs, sd) {
if (!this.bridged) {
if (!this.bridged && !this.canReleaseMedia) {
this.logger.debug('Dial:_connectSingleDial bridging endpoints');
if (this.epOther) {
this.epOther.api('uuid_break', this.epOther.uuid);
@@ -457,6 +460,9 @@ class TaskDial extends Task {
if (this.transcribeTask) this.transcribeTask.exec(cs, this.ep);
if (this.listenTask) this.listenTask.exec(cs, this.ep);
/* if we can release the media back to the SBC, do so now */
if (this.canReleaseMedia) this._releaseMedia(cs, sd);
}
_bridgeEarlyMedia(sd) {
@@ -468,6 +474,24 @@ class TaskDial extends Task {
}
}
/**
* Release the media from freeswitch
* @param {*} cs
* @param {*} sd
*/
async _releaseMedia(cs, sd) {
assert(cs.ep && sd.ep);
try {
this.logger.info('Dial:_releaseMedia - releasing media from freewitch since we can');
const aLegSdp = cs.ep.remote.sdp;
const bLegSdp = sd.ep.remote.sdp;
await Promise.all[sd.releaseMediaToSBC(aLegSdp), cs.releaseMediaToSBC(bLegSdp)];
this.epOther = null;
} catch (err) {
this.logger.info({err}, 'Dial:_releaseMedia error');
}
}
}
module.exports = TaskDial;