mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
fix race condition with filler noise and also play filler noise when idle and waiting for commands (#763)
This commit is contained in:
@@ -990,6 +990,11 @@ class CallSession extends Emitter {
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
await this._awaitCommandsOrHangup();
|
await this._awaitCommandsOrHangup();
|
||||||
|
if (this._isPlayingFillerNoise) {
|
||||||
|
this._isPlayingFillerNoise = false;
|
||||||
|
this.ep.api('uuid_break', this.ep.uuid)
|
||||||
|
.catch((err) => this.logger.info(err, 'Error killing filler noise'));
|
||||||
|
}
|
||||||
if (this.callGone) break;
|
if (this.callGone) break;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info(err, 'CallSession:exec - error waiting for new commands');
|
this.logger.info(err, 'CallSession:exec - error waiting for new commands');
|
||||||
@@ -2427,6 +2432,20 @@ Duration=${duration} `
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.logger.info('_awaitCommandsOrHangup - waiting...');
|
this.logger.info('_awaitCommandsOrHangup - waiting...');
|
||||||
this.wakeupResolver = resolve;
|
this.wakeupResolver = resolve;
|
||||||
|
|
||||||
|
/* start filler noise if configured while we wait for new commands */
|
||||||
|
if (this.fillerNoise?.url && this.ep?.connected && !this.ep2) {
|
||||||
|
this.logger.debug('CallSession:_awaitCommandsOrHangup - playing filler noise');
|
||||||
|
this._isPlayingFillerNoise = true;
|
||||||
|
this.ep.play(this.fillerNoise.url);
|
||||||
|
this.ep.once('playback-start', (evt) => {
|
||||||
|
if (evt.file === this.fillerNoise.url && !this._isPlayingFillerNoise) {
|
||||||
|
this.logger.info('CallSession:_awaitCommandsOrHangup - filler noise started');
|
||||||
|
this.ep.api('uuid_break', this.ep.uuid)
|
||||||
|
.catch((err) => this.logger.info(err, 'Error killing filler noise'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -274,6 +274,7 @@ class TaskGather extends SttTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.awaitTaskDone();
|
await this.awaitTaskDone();
|
||||||
|
this._killAudio(cs);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err, 'TaskGather:exec error');
|
this.logger.error(err, 'TaskGather:exec error');
|
||||||
}
|
}
|
||||||
@@ -703,11 +704,25 @@ class TaskGather extends SttTask {
|
|||||||
this._finalAsrTimer = null;
|
this._finalAsrTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_startFillerNoise() {
|
||||||
|
this.logger.debug('Gather:_startFillerNoise - playing filler noise');
|
||||||
|
this.ep?.play(this.fillerNoise.url);
|
||||||
|
this._fillerNoiseOn = true;
|
||||||
|
this.ep.once('playback-start', (evt) => {
|
||||||
|
if (evt.file === this.fillerNoise.url && !this._fillerNoiseOn) {
|
||||||
|
this.logger.info({evt}, 'Gather:_startFillerNoise - race condition - kill filler noise here');
|
||||||
|
this.ep.api('uuid_break', this.ep.uuid)
|
||||||
|
.catch((err) => this.logger.info(err, 'Error killing filler noise'));
|
||||||
|
return;
|
||||||
|
} else this.logger.debug({evt}, 'Gather:_startFillerNoise - playback started');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_startFillerNoiseTimer() {
|
_startFillerNoiseTimer() {
|
||||||
this._clearFillerNoiseTimer();
|
this._clearFillerNoiseTimer();
|
||||||
this._fillerNoiseTimer = setTimeout(() => {
|
this._fillerNoiseTimer = setTimeout(() => {
|
||||||
this.logger.debug('Gather:_startFillerNoiseTimer - playing filler noise');
|
this.logger.debug('Gather:_startFillerNoiseTimer - playing filler noise');
|
||||||
this.ep?.play(this.fillerNoise.url);
|
this._startFillerNoise();
|
||||||
}, this.fillerNoise.startDelaySecs * 1000);
|
}, this.fillerNoise.startDelaySecs * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -728,6 +743,7 @@ class TaskGather extends SttTask {
|
|||||||
if (this.ep?.connected && (!this.playComplete || this.hasFillerNoise)) {
|
if (this.ep?.connected && (!this.playComplete || this.hasFillerNoise)) {
|
||||||
this.logger.debug('Gather:_killAudio: killing playback of any audio');
|
this.logger.debug('Gather:_killAudio: killing playback of any audio');
|
||||||
this.playComplete = true;
|
this.playComplete = true;
|
||||||
|
this._fillerNoiseOn = false; // in a race, if we just started audio it may sneak through here
|
||||||
this.ep.api('uuid_break', this.ep.uuid)
|
this.ep.api('uuid_break', this.ep.uuid)
|
||||||
.catch((err) => this.logger.info(err, 'Error killing audio'));
|
.catch((err) => this.logger.info(err, 'Error killing audio'));
|
||||||
}
|
}
|
||||||
@@ -1090,7 +1106,7 @@ class TaskGather extends SttTask {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.debug(`TaskGather:_resolve - playing filler noise: ${this.fillerNoiseUrl}`);
|
this.logger.debug(`TaskGather:_resolve - playing filler noise: ${this.fillerNoiseUrl}`);
|
||||||
this.ep.play(this.fillerNoiseUrl);
|
this._startFillerNoise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user