Skip to content

Instantly share code, notes, and snippets.

@wiesson
Created July 8, 2016 12:36
Show Gist options
  • Save wiesson/53770cb341784933891a66ecf122d752 to your computer and use it in GitHub Desktop.
Save wiesson/53770cb341784933891a66ecf122d752 to your computer and use it in GitHub Desktop.
sipgate.io dial nodejs example
const https = require('https');
postBody = create_xml_string('49yyyyyy', '49xxxxx');
var options = {
hostname: 'api.sipgate.net',
port: 443,
path: '/RPC2',
method: 'POST',
auth: '[email protected]:password',
headers: {
'Content-Type': 'text/xml',
'Content-Length': postBody.length
}
};
var req = https.request(options, (res) => {
console.log('statusCode: ', res.statusCode);
console.log('headers: ', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
});
req.write(postBody);
req.end();
req.on('error', (e) => {
console.error(e);
});
function create_xml_string(remoteUri, localUri) {
return '<?xml version="1.0" encoding="iso-8859-1"?>' +
'<methodCall>' +
'<methodName>samurai.SessionInitiate</methodName>' +
'<params>' +
'<param>' +
'<value>' +
'<struct>' +
'<member>' +
'<name>RemoteUri</name>' +
'<value>' +
'<string>sip:' + remoteUri + '@sipgate.de</string>' +
'</value>' +
'</member>' +
'<member>' +
'<name>LocalUri</name>' +
'<value>' +
'<string>sip:' + localUri + '@sipgate.de</string>' +
'</value>' +
'</member>' +
'<member>' +
'<name>TOS</name>' +
'<value>' +
'<string>voice</string>' +
'</value>' +
'</member>' +
'</struct>' +
'</value>' +
'</param>' +
'</params>' +
'</methodCall>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment