Skip to content

Commit 6c5584b

Browse files
authored
support mod_audio_fork pause with silence (#113)
* support mod_audio_fork pause with silence parameter * support mod_audio_fork pause with silence * fix review comment * wip
1 parent f6167b6 commit 6c5584b

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

lib/endpoint.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,20 +1238,48 @@ class Endpoint extends Emitter {
12381238

12391239
/**
12401240
* Pause sending audio over the websocket connection
1241+
* @param {string} [bugname] - bugname to pause
1242+
* @param {boolean} [silence] - whether to send silence frames while paused, only applied if bugname is specified
12411243
* @param {function} [callback] - callback invoked when api request completes
12421244
* @return {Promise|Endpoint} returns a Promise if no callback supplied; otherwise
12431245
* a reference to the Endpoint object
12441246
*/
1245-
forkAudioPause(bugname, callback) {
1247+
forkAudioPause(bugname, silence, callback) {
12461248
const args = [this.uuid, 'pause'];
1249+
12471250
if (arguments.length === 1) {
1248-
// If the function is called with 1 argument, could be bugname or callback.
12491251
if (typeof bugname === 'function') {
1252+
//forkAudioPause(callback)
12501253
callback = bugname;
12511254
bugname = null;
1255+
silence = false;
1256+
} else if (typeof bugname === 'boolean') {
1257+
// forkAudioPause(silence)
1258+
silence = bugname;
1259+
bugname = null;
1260+
} else {
1261+
// forkAudioPause('my-bugname')
1262+
silence = false;
12521263
}
1264+
} else if (arguments.length === 2) {
1265+
if (typeof silence === 'function') {
1266+
callback = silence;
1267+
if (typeof bugname === 'boolean') {
1268+
// forkAudioPause(true, callback)
1269+
silence = bugname;
1270+
bugname = null;
1271+
} else {
1272+
// forkAudioPause('my-bugname', callback)
1273+
silence = false;
1274+
}
1275+
}
1276+
//forkAudioPause('my-bugname', true)
1277+
}
1278+
//forkAudioPause('my-bugname', true, callback)
1279+
if (bugname) {
1280+
args.push(bugname);
1281+
args.push(silence ? 'silence' : 'blank');
12531282
}
1254-
if (bugname) args.push(bugname);
12551283

12561284
const __x = (callback) => {
12571285
debug(`calling uuid_audio_fork with args ${JSON.stringify(args)}`);

test/endpoint.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,28 @@ test.skip('fork audio', (t) => {
507507
.then((evt) => {
508508
return ep.forkAudioStop();
509509
})
510+
// pause, resume
511+
.then(() => {
512+
t.pass('stopped forking audio with no metadata');
513+
return ep.forkAudioStart({
514+
wsUrl: 'ws://ws-server:3001',
515+
mixType: 'stereo',
516+
sampling: '16000'
517+
});
518+
})
519+
.then(() => {
520+
t.pass('started forking audio with no metadata');
521+
return uac.playFile('voicemail/16000/vm-record_message.wav');
522+
})
523+
.then((evt) => {
524+
return ep.forkAudioPause('background_record', true);
525+
})
526+
.then((evt) => {
527+
return ep.forkAudioResume();
528+
})
529+
.then((evt) => {
530+
return ep.forkAudioStop();
531+
})
510532
.then(() => {
511533
t.pass('stopped forking audio with no metadata');
512534
return ;

0 commit comments

Comments
 (0)