I have a stasis app that has successfully places a channel in two bridges, while adding an external media channel(different ports) in each bridge. Ideally, each bridge was going to facilitate audio in one direction for a later use. This is all on the same machine. However, I have only been able to get rtp packets OUT of the external media channel. I have 2 node.js scripts testing rtp in both ways, one is saving them from port 12345. The other script is sending packets to 12346.
My RTP debug output shows:
Got RTP packet from 192.168.1.24:5004 (type 00, seq 019609, ts 009643, len 000160) Sent RTP packet to 192.168.1.24:5004 (type 00, seq 017127, ts 001600, len 000160) Sent RTP packet to 127.0.0.1:12345 (type 118, seq 005665, ts 3680512, len 000640) Sent RTP packet to 127.0.0.1:12346 (type 118, seq 027327, ts 3680512, len 000640) Got RTP packet from 192.168.1.24:5004 (type 00, seq 019610, ts 009803, len 000160) Sent RTP packet to 192.168.1.24:5004 (type 00, seq 017128, ts 001760, len 000160) Sent RTP packet to 127.0.0.1:12346 (type 118, seq 027328, ts 3680832, len 000640) Sent RTP packet to 127.0.0.1:12345 (type 118, seq 005666, ts 3680832, len 000640) Got RTP packet from 192.168.1.24:5004 (type 00, seq 019611, ts 009963, len 000160) Sent RTP packet to 127.0.0.1:12346 (type 118, seq 027329, ts 3681152, len 000640) Sent RTP packet to 192.168.1.24:5004 (type 00, seq 017129, ts 001920, len 000160) Sent RTP packet to 127.0.0.1:12345 (type 118, seq 005667, ts 3681152, len 000640) Got RTP packet from 192.168.1.24:5004 (type 00, seq 019612, ts 010123, len 000160)
Which is half of what im trying to do. The audio is great when I receive it, but I cannot get any packets into the call. My first thought is that im a silly guy, and maybe ive missed something in rtp.conf or something similar. My second thought is this extends beyond the intended purposes of external media channels, but that doesnt seem right.
Where could i find additional logs pertaining to this? using tcpdump I can verify packets are flowing and should be picked up by the corresponding external media channel. Maybe im not configureing the packets correct? My hope is i would get SOME audio, distorted or otherwise if that was the case.
Heres the ari anycase that is relevant
`const ari = require(‘ari-client’);
// Configuration
const ARI_URL = ‘http://localhost:8088’;
const USERNAME = ‘xxx’;
const PASSWORD = ‘xxx’;
const STASIS_APP = ‘discord_bridge’;
const EXTERNAL_MEDIA_HOST = ‘127.0.0.1:12345’;
const EXTERNAL_MEDIA_FORMAT = ‘slin16’;
const activeBridges = {}; // Track bridges and external media status
ari.connect(ARI_URL, USERNAME, PASSWORD, function (err, client) {
if (err) {
console.error(‘Error connecting to ARI:’, err);
return;
}
console.log('Connected to Asterisk ARI');
client.on('StasisStart', function (event, incoming) {
console.log(`Incoming channel ${incoming.id} entered Stasis`);
incoming.answer(function (err) {
if (err) {
console.error(`Error answering call: ${err}`);
return;
}
setupBridge(incoming);
});
});
function setupBridge(channel) {
client.bridges.list(function (err, bridges) {
if (err) {
console.error('Error listing bridges:', err);
return;
}
// Find the first existing mixing bridge, or create one if it doesn't exist
let bridge = bridges.find(b => b.bridge_type === 'mixing');
if (!bridge) {
bridge = client.Bridge();
bridge.create({ type: 'mixing' }, function (err, newBridge) {
if (err) {
console.error('Error creating bridge:', err);
return;
}
console.log(`Created new bridge: ${newBridge.id}`);
activeBridges[newBridge.id] = { hasExternalMedia: false };
joinBridge(newBridge, channel);
});
} else {
console.log(`Using existing bridge: ${bridge.id}`);
joinBridge(bridge, channel);
}
// Add a second bridge for external media with port 12346
let secondBridge = bridges.find(b => b.bridge_type === 'mixing' && b.id !== bridge.id);
if (!secondBridge) {
secondBridge = client.Bridge();
secondBridge.create({ type: 'mixing' }, function (err, newBridge) {
if (err) {
console.error('Error creating second bridge:', err);
return;
}
console.log(`Created new second bridge: ${newBridge.id}`);
activeBridges[newBridge.id] = { hasExternalMedia: false };
joinSecondBridge(newBridge, channel);
});
} else {
console.log(`Using existing second bridge: ${secondBridge.id}`);
joinSecondBridge(secondBridge, channel);
}
});
}
function joinBridge(bridge, channel) {
bridge.addChannel({ channel: channel.id }, function (err) {
if (err) {
console.error(`Error adding channel to bridge: ${err}`);
return;
}
console.log(`Added channel ${channel.id} to bridge ${bridge.id}`);
// Only create external media if not already added
if (!activeBridges[bridge.id]?.hasExternalMedia) {
activeBridges[bridge.id].hasExternalMedia = true;
createExternalMedia(bridge);
}
});
}
function joinSecondBridge(bridge, channel) {
bridge.addChannel({ channel: channel.id }, function (err) {
if (err) {
console.error(`Error adding channel to second bridge: ${err}`);
return;
}
console.log(`Added channel ${channel.id} to second bridge ${bridge.id}`);
// Only create external media if not already added
if (!activeBridges[bridge.id]?.hasExternalMedia) {
activeBridges[bridge.id].hasExternalMedia = true;
createSecondExternalMedia(bridge);
}
});
}
function createExternalMedia(bridge) {
client.channels.externalMedia({
app: STASIS_APP,
external_host: EXTERNAL_MEDIA_HOST,
format: EXTERNAL_MEDIA_FORMAT
}, function (err, externalMediaChannel) {
if (err) {
console.error('Error creating external media channel:', err);
return;
}
console.log(`Created external media channel: ${externalMediaChannel.id}`);
bridge.addChannel({ channel: externalMediaChannel.id }, function (err) {
if (err) {
console.error(`Error adding external media channel to bridge: ${err}`);
return;
}
console.log(`Added external media channel ${externalMediaChannel.id} to bridge ${bridge.id}`);
});
});
}
function createSecondExternalMedia(bridge) {
client.channels.externalMedia({
app: STASIS_APP,
external_host: '127.0.0.1:12346', // External media with different port
format: EXTERNAL_MEDIA_FORMAT
}, function (err, externalMediaChannel) {
if (err) {
console.error('Error creating second external media channel:', err);
return;
}
console.log(`Created second external media channel: ${externalMediaChannel.id}`);
bridge.addChannel({ channel: externalMediaChannel.id }, function (err) {
if (err) {
console.error(`Error adding second external media channel to bridge: ${err}`);
return;
}
console.log(`Added second external media channel ${externalMediaChannel.id} to bridge ${bridge.id}`);
});
});
}
client.start(STASIS_APP);
});
`