mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-22 01:27:55 +00:00
initial WIP to remove freeswitch from media path when not recording or transcribing dial calls
This commit is contained in:
@@ -926,6 +926,17 @@ class CallSession extends Emitter {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async releaseMediaToSBC(remoteSdp) {
|
||||||
|
assert(this.dlg);
|
||||||
|
assert(this.dlg.connected);
|
||||||
|
assert(this.ep);
|
||||||
|
assert(typeof remoteSdp === 'string');
|
||||||
|
await this.dlg.modify(remoteSdp);
|
||||||
|
this.ep.destroy()
|
||||||
|
.then(() => this.ep = null)
|
||||||
|
.catch((err) => this.logger.error({err}, 'releaseMediaToSBC: Error destroying endpoint'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called any time call status changes. This method both invokes the
|
* Called any time call status changes. This method both invokes the
|
||||||
* call_status_hook callback as well as updates the realtime database
|
* call_status_hook callback as well as updates the realtime database
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ class TaskDial extends Task {
|
|||||||
|
|
||||||
get name() { return TaskName.Dial; }
|
get name() { return TaskName.Dial; }
|
||||||
|
|
||||||
|
get canReleaseMedia() { return !this.dtmfHook && !this.listenTask && !this.transcribeTask; }
|
||||||
|
|
||||||
async exec(cs) {
|
async exec(cs) {
|
||||||
await super.exec(cs);
|
await super.exec(cs);
|
||||||
try {
|
try {
|
||||||
@@ -255,7 +257,8 @@ class TaskDial extends Task {
|
|||||||
debug(`Dial:__initializeInbound allocated ep for incoming call: ${ep.uuid}`);
|
debug(`Dial:__initializeInbound allocated ep for incoming call: ${ep.uuid}`);
|
||||||
|
|
||||||
/* send outbound legs back to the same SBC (to support static IP feature) */
|
/* 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) {
|
if (this.dialMusic) {
|
||||||
// play dial music to caller while we outdial
|
// play dial music to caller while we outdial
|
||||||
@@ -395,7 +398,7 @@ class TaskDial extends Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_connectSingleDial(cs, sd) {
|
_connectSingleDial(cs, sd) {
|
||||||
if (!this.bridged) {
|
if (!this.bridged && !this.canReleaseMedia) {
|
||||||
this.logger.debug('Dial:_connectSingleDial bridging endpoints');
|
this.logger.debug('Dial:_connectSingleDial bridging endpoints');
|
||||||
if (this.epOther) {
|
if (this.epOther) {
|
||||||
this.epOther.api('uuid_break', this.epOther.uuid);
|
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.transcribeTask) this.transcribeTask.exec(cs, this.ep);
|
||||||
if (this.listenTask) this.listenTask.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) {
|
_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;
|
module.exports = TaskDial;
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class SingleDialer extends Emitter {
|
|||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
opts.headers = opts.headers || {};
|
opts.headers = opts.headers || {};
|
||||||
opts.headers = {...opts.headers, 'X-Call-Sid': this.callSid};
|
opts.headers = {...opts.headers, 'X-Call-Sid': this.callSid};
|
||||||
|
this.ms = ms;
|
||||||
let uri, to;
|
let uri, to;
|
||||||
try {
|
try {
|
||||||
switch (this.target.type) {
|
switch (this.target.type) {
|
||||||
@@ -313,6 +314,17 @@ class SingleDialer extends Emitter {
|
|||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async releaseMediaToSBC(remoteSdp) {
|
||||||
|
assert(this.dlg);
|
||||||
|
assert(this.dlg.connected);
|
||||||
|
assert(this.ep);
|
||||||
|
assert(typeof remoteSdp === 'string');
|
||||||
|
await this.dlg.modify(remoteSdp);
|
||||||
|
this.ep.destroy()
|
||||||
|
.then(() => this.ep = null)
|
||||||
|
.catch((err) => this.logger.error({err}, 'releaseMediaToSBC: Error destroying endpoint'));
|
||||||
|
}
|
||||||
|
|
||||||
_notifyCallStatusChange({callStatus, sipStatus, duration}) {
|
_notifyCallStatusChange({callStatus, sipStatus, duration}) {
|
||||||
assert((typeof duration === 'number' && callStatus === CallStatus.Completed) ||
|
assert((typeof duration === 'number' && callStatus === CallStatus.Completed) ||
|
||||||
(!duration && callStatus !== CallStatus.Completed),
|
(!duration && callStatus !== CallStatus.Completed),
|
||||||
|
|||||||
12
package-lock.json
generated
12
package-lock.json
generated
@@ -592,9 +592,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ansi-regex": {
|
"node_modules/ansi-regex": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
@@ -5239,9 +5239,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"ansi-regex": {
|
"ansi-regex": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"ansi-styles": {
|
"ansi-styles": {
|
||||||
|
|||||||
Reference in New Issue
Block a user