So I’m using Asterisk to initiate outbound calls through my external SIP, it works and the call goes outbound and I do receive it. But whenever I pick up the call it calls me again while I’m on the call and plays the ringing audio from the other call and whatever other sounds come into play.
So, I’m wondering how on earth I’m meant to stop this. I’ve tried 2 libraries and they both have this issue so it’s not specific to the libraries. Below is my code and configs:
const AMI = require("asterisk-manager");
const config = {`Preformatted text`
host: "",
port: 5038,
login: "",
password: "",
};
const ami = new AMI(
config.port,
config.host,
config.login,
config.password,
true
);
ami.keepConnected();
ami.on("connect", () => {
console.log("AMI is connected");
});
ami.on("error", (err) => {
console.error("AMI Connection Error:", err);
});
module.exports = async (number) => {
if (!ami.connected) {
console.log("Waiting for AMI to connect...");
await waitForConnection();
}
const actionId = `call-${number}-${Date.now()}`;
ami.action(
{
action: "Originate",
channel: `SIP/privatesip/${number}`,
context: "outbound",
exten: number,
priority: 1,
actionid: actionId,
},
(err, res) => {
if (err) {
console.error("Originate Error:", err);
} else {
console.log("Originate Response:", res);
}
}
);
};
function waitForConnection() {
return new Promise((resolve) => {
const check = setInterval(() => {
if (ami.connected) {
clearInterval(check);
resolve();
}
}, 1000);
});
}
sip.conf
[general]
externip = MY_SERVER_IP
localnet = 192.168.1.0/255.255.255.0
nat = yes
externrefresh = 180
session-timers = refuse
[privatesip]
type = peer
host = MY_HOST
username = MY_USERNAME
secret = MY_PASSWORD
fromuser = MY_USERNAME
fromdomain = MY_HOST
context = outbound
insecure = port,invite
nat = force_rport,comedia
disallow = all
allow = ulaw
canreinvite = no
extensions.conf
[general]
autofallthrough=yes ; Automatically fall through if no match found
[outbound]
exten => _X.,1,Dial(SIP/${EXTEN}@privatesip,60)
exten => _X.,n,Hangup()