mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
Fix/play timeout (#183)
* Move play timeout into jambonz * Unnecessary await on kill + eslint * Change call status test to be consistent Co-authored-by: Matt Preskett <matt.preskett@netcall.com>
This commit is contained in:
@@ -114,6 +114,10 @@ class CallSession extends Emitter {
|
|||||||
return this.callInfo.applicationSid;
|
return this.callInfo.applicationSid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get callStatus() {
|
||||||
|
return this.callInfo.callStatus;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SIP call-id for the call
|
* SIP call-id for the call
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const Task = require('./task');
|
const Task = require('./task');
|
||||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
const {TaskName, TaskPreconditions, CallStatus} = require('../utils/constants');
|
||||||
|
|
||||||
class TaskPlay extends Task {
|
class TaskPlay extends Task {
|
||||||
constructor(logger, opts) {
|
constructor(logger, opts) {
|
||||||
@@ -22,6 +22,20 @@ class TaskPlay extends Task {
|
|||||||
async exec(cs, {ep}) {
|
async exec(cs, {ep}) {
|
||||||
await super.exec(cs);
|
await super.exec(cs);
|
||||||
this.ep = ep;
|
this.ep = ep;
|
||||||
|
let timeout;
|
||||||
|
let playbackSeconds = 0;
|
||||||
|
let playbackMilliseconds = 0;
|
||||||
|
let completed = !(this.timeoutSecs > 0 || this.loop);
|
||||||
|
if (this.timeoutSecs > 0) {
|
||||||
|
timeout = setTimeout(async() => {
|
||||||
|
completed = true;
|
||||||
|
try {
|
||||||
|
await this.kill(cs);
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.info(err, 'Error killing audio on timeoutSecs');
|
||||||
|
}
|
||||||
|
}, this.timeoutSecs * 1000);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
while (!this.killed && (this.loop === 'forever' || this.loop--) && this.ep.connected) {
|
while (!this.killed && (this.loop === 'forever' || this.loop--) && this.ep.connected) {
|
||||||
if (cs.isInConference) {
|
if (cs.isInConference) {
|
||||||
@@ -34,14 +48,24 @@ class TaskPlay extends Task {
|
|||||||
await this.playToConfMember(this.ep, memberId, confName, confUuid, this.url);
|
await this.playToConfMember(this.ep, memberId, confName, confUuid, this.url);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const file = (this.timeoutSecs >= 0 || this.seekOffset >= 0) ?
|
let file = this.url;
|
||||||
{file: this.url, seekOffset: this.seekOffset, timeoutSecs: this.timeoutSecs} : this.url;
|
if (this.seekOffset >= 0) {
|
||||||
|
file = {file: this.url, seekOffset: this.seekOffset};
|
||||||
|
this.seekOffset = -1;
|
||||||
|
}
|
||||||
const result = await ep.play(file);
|
const result = await ep.play(file);
|
||||||
await this.performAction(Object.assign(result, {reason: 'playCompleted'}),
|
playbackSeconds += parseInt(result.playbackSeconds);
|
||||||
|
playbackMilliseconds += parseInt(result.playbackMilliseconds);
|
||||||
|
if (this.killed || !this.loop || completed) {
|
||||||
|
if (timeout) clearTimeout(timeout);
|
||||||
|
await this.performAction(
|
||||||
|
Object.assign(result, {reason: 'playCompleted', playbackSeconds, playbackMilliseconds}),
|
||||||
!(this.parentTask || cs.isConfirmCallSession));
|
!(this.parentTask || cs.isConfirmCallSession));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (timeout) clearTimeout(timeout);
|
||||||
this.logger.info(err, `TaskPlay:exec - error playing ${this.url}`);
|
this.logger.info(err, `TaskPlay:exec - error playing ${this.url}`);
|
||||||
}
|
}
|
||||||
this.emit('playDone');
|
this.emit('playDone');
|
||||||
|
|||||||
Reference in New Issue
Block a user