mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
add support for bidirectional audio when using listen verb
This commit is contained in:
@@ -122,6 +122,11 @@ class TaskListen extends Task {
|
|||||||
if (this.finishOnKey || this.passDtmf) {
|
if (this.finishOnKey || this.passDtmf) {
|
||||||
ep.on('dtmf', this._dtmfHandler);
|
ep.on('dtmf', this._dtmfHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* support bi-directional audio */
|
||||||
|
ep.addCustomEventListener(ListenEvents.PlayAudio, this._onPlayAudio.bind(this, ep));
|
||||||
|
ep.addCustomEventListener(ListenEvents.KillAudio, this._onKillAudio.bind(this, ep));
|
||||||
|
ep.addCustomEventListener(ListenEvents.Disconnect, this._onDisconnect.bind(this, ep));
|
||||||
}
|
}
|
||||||
|
|
||||||
_removeListeners(ep) {
|
_removeListeners(ep) {
|
||||||
@@ -154,6 +159,29 @@ class TaskListen extends Task {
|
|||||||
this.logger.info(evt, 'TaskListen:_onConnectFailure');
|
this.logger.info(evt, 'TaskListen:_onConnectFailure');
|
||||||
this.notifyTaskDone();
|
this.notifyTaskDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _onPlayAudio(ep, evt) {
|
||||||
|
this.logger.info(`received play_audio event: ${JSON.stringify(evt)}`);
|
||||||
|
try {
|
||||||
|
const results = await ep.play(evt.file);
|
||||||
|
this.logger.debug(`Finished playing file, result: ${JSON.stringify(results)}`);
|
||||||
|
ep.forkAudioSendText({type: 'playDone', data: Object.assign({id: evt.id}, results)});
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this.logger.error({err}, 'Error playing file');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onKillAudio(ep) {
|
||||||
|
this.logger.info('received kill_audio event');
|
||||||
|
ep.api('uuid_break', ep.uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onDisconnect(ep, cs) {
|
||||||
|
this.logger.debug('_onDisconnect: TaskListen terminating task');
|
||||||
|
this.kill(cs);
|
||||||
|
}
|
||||||
|
|
||||||
_onError(ep, evt) {
|
_onError(ep, evt) {
|
||||||
this.logger.info(evt, 'TaskListen:_onError');
|
this.logger.info(evt, 'TaskListen:_onError');
|
||||||
this.notifyTaskDone();
|
this.notifyTaskDone();
|
||||||
|
|||||||
Reference in New Issue
Block a user