mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
add support for ws verb:status event notifications (#196)
This commit is contained in:
@@ -63,6 +63,7 @@ class CallSession extends Emitter {
|
||||
assert(rootSpan);
|
||||
|
||||
this._recordState = RecordState.RecordingOff;
|
||||
this._notifyEvents = false;
|
||||
|
||||
this.tmpFiles = new Set();
|
||||
|
||||
@@ -265,6 +266,9 @@ class CallSession extends Emitter {
|
||||
|
||||
get recordState() { return this._recordState; }
|
||||
|
||||
get notifyEvents() { return this._notifyEvents; }
|
||||
set notifyEvents(notify) { this._notifyEvents = !!notify; }
|
||||
|
||||
set globalSttHints({hints, hintsBoost}) {
|
||||
this._globalSttHints = {hints, hintsBoost};
|
||||
}
|
||||
@@ -612,6 +616,7 @@ class CallSession extends Emitter {
|
||||
const stackNum = this.stackIdx;
|
||||
const task = this.tasks.shift();
|
||||
this.logger.info(`CallSession:exec starting task #${stackNum}:${taskNum}: ${task.name}`);
|
||||
this._notifyTaskStatus(task, {event: 'starting'});
|
||||
try {
|
||||
const resources = await this._evaluatePreconditions(task);
|
||||
let skip = false;
|
||||
@@ -635,6 +640,7 @@ class CallSession extends Emitter {
|
||||
}
|
||||
this.currentTask = null;
|
||||
this.logger.info(`CallSession:exec completed task #${stackNum}:${taskNum}: ${task.name}`);
|
||||
this._notifyTaskStatus(task, {event: 'finished'});
|
||||
} catch (err) {
|
||||
task.span?.end();
|
||||
this.currentTask = null;
|
||||
@@ -1623,6 +1629,25 @@ class CallSession extends Emitter {
|
||||
.catch((err) => this.logger.error(err, 'redis error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* notifyTaskError - only used when websocket connection is used instead of webhooks
|
||||
*/
|
||||
|
||||
_notifyTaskError(obj) {
|
||||
if (this.requestor instanceof WsRequestor) {
|
||||
this.requestor.request('jambonz:error', '/error', obj)
|
||||
.catch((err) => this.logger.debug({err}, 'CallSession:_notifyTaskError - Error sending'));
|
||||
}
|
||||
}
|
||||
|
||||
_notifyTaskStatus(task, evt) {
|
||||
if (this.notifyEvents && this.requestor instanceof WsRequestor) {
|
||||
const obj = {...evt, id: task.id, name: task.name};
|
||||
this.requestor.request('verb:status', '/status', obj)
|
||||
.catch((err) => this.logger.debug({err}, 'CallSession:_notifyTaskStatus - Error sending'));
|
||||
}
|
||||
}
|
||||
|
||||
_awaitCommandsOrHangup() {
|
||||
assert(!this.wakeupResolver);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user