Fix for play issue (#1223)

See https://github.com/jambonz/jambonz-feature-server/issues/1222
This commit is contained in:
rammohan-y
2025-05-29 20:02:03 +05:30
committed by GitHub
parent 4386df993c
commit e975511df5
2 changed files with 9 additions and 1 deletions

View File

@@ -83,6 +83,7 @@ class CallSession extends Emitter {
this.stickyEventEmitter = new StickyEventEmitter();
this.stickyEventEmitter.onSuccess = () => {
this.taskInProgress = null;
this.stickyEventEmitter.destroy();
};
this.backgroundTaskManager = new BackgroundTaskManager({
cs: this,
@@ -1927,10 +1928,12 @@ Duration=${duration} `
this.stackIdx++;
this.logger.debug({tasks: listTaskNames(tasks)},
`CallSession:replaceApplication reset with ${tasks.length} new tasks, stack depth is ${this.stackIdx}`);
let curTaskKilled = false;
if (this.currentTask) {
this.logger.debug('CallSession:replaceApplication - killing current task ' +
this.currentTask?.name + ', taskId: ' + this.currentTask.taskId);
this.currentTask.kill(this, KillReason.Replaced);
curTaskKilled = true;
this.currentTask = null;
}
else if (this.wakeupResolver) {
@@ -1938,7 +1941,8 @@ Duration=${duration} `
this.wakeupResolver({reason: 'new tasks'});
this.wakeupResolver = null;
}
if ((!this.currentTask || this.currentTask === undefined) && this.isCurTaskPlay) {
// if currentTask which is play, already got killed, no need to call uuid_break
if (!curTaskKilled && (!this.currentTask || this.currentTask === undefined) && this.isCurTaskPlay) {
this.logger.debug(`CallSession:replaceApplication - emitting uuid_break, taskId: ${this.taskInProgress?.taskId}`);
this.stickyEventEmitter.emit('uuid_break', this.taskInProgress);
}

View File

@@ -37,6 +37,10 @@ class StickyEventEmitter extends EventEmitter {
this.onSuccess();
}
this._onceListeners.delete(event);
// return from here as the event listener is already called
// this is to avoid calling the native emit method which
// will call the event listener again
return true;
}
return super.emit(event, ...args);