@jambonz/mrf 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/endpoint.js +14 -5
- package/package.json +1 -1
package/lib/endpoint.js
CHANGED
|
@@ -46,12 +46,16 @@ class Endpoint extends EventEmitter {
|
|
|
46
46
|
seekOffset = file.seekOffset;
|
|
47
47
|
file = file.file;
|
|
48
48
|
}
|
|
49
|
-
const
|
|
49
|
+
const files = Array.isArray(file) ? file : [file];
|
|
50
|
+
const urls = files.map(translatePlayUrl);
|
|
50
51
|
const data = { urls };
|
|
51
52
|
if (seekOffset > 0) data.seekOffset = parseInt(seekOffset, 10);
|
|
52
53
|
const { playId } = await this._request('play.start', data);
|
|
53
54
|
return new Promise((resolve, reject) => {
|
|
54
|
-
|
|
55
|
+
// file (the caller's original, untranslated path) rides on the
|
|
56
|
+
// playback-start/stop events: FS parity — the say/play tasks match
|
|
57
|
+
// events to plays by evt.file when there is no tts playback id
|
|
58
|
+
this._pendingPlays.set(playId, { resolve, reject, file: files[0] });
|
|
55
59
|
});
|
|
56
60
|
}
|
|
57
61
|
|
|
@@ -457,9 +461,12 @@ class Endpoint extends EventEmitter {
|
|
|
457
461
|
case 'dtmf':
|
|
458
462
|
this.emit('dtmf', { dtmf: data.digit, duration: data.durationMs, source: data.source });
|
|
459
463
|
break;
|
|
460
|
-
case 'play.start':
|
|
461
|
-
|
|
464
|
+
case 'play.start': {
|
|
465
|
+
const file = this._pendingPlays.get(data.playId)?.file;
|
|
466
|
+
this.emit('playback-start',
|
|
467
|
+
{ playId: data.playId, ...(file && {file}), ...ttsVars(data.tts) });
|
|
462
468
|
break;
|
|
469
|
+
}
|
|
463
470
|
case 'play.done': {
|
|
464
471
|
const p = this._pendingPlays.get(data.playId);
|
|
465
472
|
if (p) {
|
|
@@ -475,7 +482,9 @@ class Endpoint extends EventEmitter {
|
|
|
475
482
|
playbackLastOffsetPos: data.lastOffsetPos ?? 0
|
|
476
483
|
});
|
|
477
484
|
}
|
|
478
|
-
this.emit('playback-stop',
|
|
485
|
+
this.emit('playback-stop',
|
|
486
|
+
{ playId: data.playId, reason: data.reason, ...(p?.file && {file: p.file}),
|
|
487
|
+
...ttsVars(data.tts) });
|
|
479
488
|
break;
|
|
480
489
|
}
|
|
481
490
|
default: {
|