mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2025-12-19 04:27:46 +00:00
95 lines
2.4 KiB
JavaScript
95 lines
2.4 KiB
JavaScript
const { spawn } = require('child_process');
|
|
const debug = require('debug')('jambonz:ci');
|
|
let network;
|
|
const obj = {};
|
|
let output = '';
|
|
let idx = 1;
|
|
|
|
function clearOutput() {
|
|
output = '';
|
|
}
|
|
|
|
function addOutput(str) {
|
|
for (let i = 0; i < str.length; i++) {
|
|
if (str.charCodeAt(i) < 128) output += str.charAt(i);
|
|
}
|
|
}
|
|
|
|
module.exports = (networkName) => {
|
|
network = networkName ;
|
|
return obj;
|
|
};
|
|
|
|
obj.output = () => {
|
|
return output;
|
|
};
|
|
|
|
obj.sippUac = (file, regObj, bindAddress, injectionFile) => {
|
|
const cmd = 'docker';
|
|
let args = null;
|
|
if(regObj) {
|
|
args = [
|
|
'run', '--rm', '--net', `${network}`,
|
|
'-v', `${__dirname}/scenarios:/tmp/scenarios`,
|
|
'drachtio/sipp', 'sipp', `${regObj.remote_host}`, // remote host is require on auth
|
|
'-inf', `/tmp/scenarios/${regObj.data_file}`,
|
|
'-sf', `/tmp/scenarios/${file}`,
|
|
'-m', '1',
|
|
'-sleep', '250ms',
|
|
'-nostdin',
|
|
'-cid_str', `%u-%p@%s-${idx++}`,
|
|
'sbc', '-trace_msg'
|
|
];
|
|
} else if (injectionFile) {
|
|
args = [
|
|
'run', '-t', '--rm', '--net', `${network}`,
|
|
'-v', `${__dirname}/scenarios:/tmp/scenarios`,
|
|
'drachtio/sipp', 'sipp', '-sf', `/tmp/scenarios/${file}`,
|
|
'-inf', `/tmp/scenarios/${injectionFile}`,
|
|
'-m', '1',
|
|
'-sleep', '250ms',
|
|
'-nostdin',
|
|
'-cid_str', `%u-%p@%s-${idx++}`,
|
|
'172.39.0.10'];
|
|
}
|
|
else {
|
|
args = [
|
|
'run', '-t', '--rm', '--net', `${network}`,
|
|
'-v', `${__dirname}/scenarios:/tmp/scenarios`,
|
|
'drachtio/sipp', 'sipp', '-sf', `/tmp/scenarios/${file}`,
|
|
'-m', '1',
|
|
'-sleep', '250ms',
|
|
'-nostdin',
|
|
'-cid_str', `%u-%p@%s-${idx++}`,
|
|
'172.39.0.10'];
|
|
}
|
|
|
|
if (bindAddress) args.splice(5, 0, '--ip', bindAddress);
|
|
|
|
clearOutput();
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const child_process = spawn(cmd, args, {stdio: ['inherit', 'pipe', 'pipe']});
|
|
|
|
child_process.on('exit', (code, signal) => {
|
|
if (code === 0) {
|
|
return resolve();
|
|
}
|
|
console.log(`sipp exited with non-zero code ${code} signal ${signal}`);
|
|
reject(code);
|
|
});
|
|
child_process.on('error', (error) => {
|
|
console.log(`error spawing child process for docker: ${args}`);
|
|
});
|
|
|
|
child_process.stdout.on('data', (data) => {
|
|
debug(`stdout: ${data}`);
|
|
addOutput(data.toString());
|
|
});
|
|
child_process.stderr.on('data', (data) => {
|
|
debug(`stderr: ${data}`);
|
|
addOutput(data.toString());
|
|
});
|
|
});
|
|
};
|