使用 NPM 的内置dns 模块,我能够让事情正常进行。这就是我的函数现在的样子。似乎工作正常。
const dns = require('dns');
let sipUri = '1777xxxxxxxxxx@in.callcentric.com';
let protocol = 'udp';
let region = 'us2' ;
exports.handler = function(context, event, callback) {
var user = sipUri.split('@')[0];
var host = sipUri.split('@')[1];
// generate the TwiML to tell Twilio how to forward this call
let twiml = new Twilio.twiml.VoiceResponse();
const dial = twiml.dial();
dns.resolveSrv('_sip._'+protocol+'.'+host, (err, addresses) => {
var resolvedhost = addresses[0].name+':'+addresses[0].port;
dial.sip('sip:'+user+'@'+resolvedhost+';region='+region);
console.log(twiml.toString());
// return the TwiML
callback(null, twiml);
});
};
这会手动查询 SRV 记录的主机名,然后使用返回的第一个结果。不考虑权重和优先级。
要旨