mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
play verb: fix race condition where play canceled immediately after start
This commit is contained in:
@@ -211,7 +211,7 @@ class TaskLlmUltravox_S2S extends Task {
|
|||||||
async _onServerEvent(_ep, evt) {
|
async _onServerEvent(_ep, evt) {
|
||||||
let endConversation = false;
|
let endConversation = false;
|
||||||
const type = evt.type;
|
const type = evt.type;
|
||||||
this.logger.debug({evt}, 'TaskLlmUltravox_S2S:_onServerEvent');
|
//this.logger.debug({evt}, 'TaskLlmUltravox_S2S:_onServerEvent');
|
||||||
|
|
||||||
/* server errors of some sort */
|
/* server errors of some sort */
|
||||||
if (type === 'error') {
|
if (type === 'error') {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const Task = require('./task');
|
const Task = require('./task');
|
||||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||||
const { PlayFileNotFoundError } = require('../utils/error');
|
const { PlayFileNotFoundError } = require('../utils/error');
|
||||||
|
const { performance } = require('perf_hooks');
|
||||||
|
|
||||||
class TaskPlay extends Task {
|
class TaskPlay extends Task {
|
||||||
constructor(logger, opts) {
|
constructor(logger, opts) {
|
||||||
@@ -55,6 +56,7 @@ class TaskPlay extends Task {
|
|||||||
file = {file: this.url, seekOffset: this.seekOffset};
|
file = {file: this.url, seekOffset: this.seekOffset};
|
||||||
this.seekOffset = -1;
|
this.seekOffset = -1;
|
||||||
}
|
}
|
||||||
|
this._playbackSent = performance.now();
|
||||||
const result = await ep.play(file);
|
const result = await ep.play(file);
|
||||||
playbackSeconds += parseInt(result.playbackSeconds);
|
playbackSeconds += parseInt(result.playbackSeconds);
|
||||||
playbackMilliseconds += parseInt(result.playbackMilliseconds);
|
playbackMilliseconds += parseInt(result.playbackMilliseconds);
|
||||||
@@ -95,7 +97,14 @@ class TaskPlay extends Task {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.notifyStatus({event: 'kill-playback'});
|
this.notifyStatus({event: 'kill-playback'});
|
||||||
|
const now = performance.now();
|
||||||
|
if (this._playbackSent && now - this._playbackSent < 30) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.logger.debug('TaskPlay:kill - sending uuid_break after brief delay due to quick cancel');
|
||||||
this.ep.api('uuid_break', this.ep.uuid).catch((err) => this.logger.info(err, 'Error killing audio'));
|
this.ep.api('uuid_break', this.ep.uuid).catch((err) => this.logger.info(err, 'Error killing audio'));
|
||||||
|
}, 30);
|
||||||
|
}
|
||||||
|
else this.ep.api('uuid_break', this.ep.uuid).catch((err) => this.logger.info(err, 'Error killing audio'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ class WsRequestor extends BaseRequestor {
|
|||||||
|
|
||||||
/* send the message */
|
/* send the message */
|
||||||
this.ws.send(JSON.stringify(obj), async() => {
|
this.ws.send(JSON.stringify(obj), async() => {
|
||||||
this.logger.debug({obj}, `WsRequestor:request websocket: sent (${url})`);
|
//this.logger.debug({obj}, `WsRequestor:request websocket: sent (${url})`);
|
||||||
// If session:reconnect is waiting for ack, hold here until ack to send queuedMsgs
|
// If session:reconnect is waiting for ack, hold here until ack to send queuedMsgs
|
||||||
if (this._reconnectPromise) {
|
if (this._reconnectPromise) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user