I am developing an ARI application to get real-time transcription, which is working fine with ChanSpy. Now I want to do the same in ARI, maybe using SnoopChannel, but I could not find any proper guide about it. I just want to know after which event we have to start snooping on a channel in ARI or any guide about it.
I am using same code from asterisk external media from guthub.
const client = require('ari-client');
const EventEmitter = require('events');
class AriController extends EventEmitter {
constructor(options) {
super();
this.options = Object.assign({}, options);
}
async close() {
if (this.closing) {
return;
}
this.closing = true;
if (this.localChannel) {
console.log("Hanging up local channel");
try {
await this.localChannel.hangup();
} catch (error) {
}
delete this.localChannel;
}
if (this.externalChannel) {
console.log("Hanging up external media channel");
try {
await this.externalChannel.hangup();
} catch (error) {
}
delete this.externalChannel;
}
if (this.bridge) {
console.log("Destroying bridge");
try {
await this.bridge.destroy();
} catch (error) {
}
delete this.bridge;
}
if (this.options.closeCallback) {
this.options.closeCallback();
}
await this.ari.stop();
this.emit('close');
}
async connect() {
this.ari = await client.connect(
this.options.ariServerUrl, this.options.ariUser, this.options.ariPassword);
await this.ari.start("externalMedia");
// Create a simple bridge that is controlled by ARI/Stasis
this.bridge = this.ari.Bridge();
try {
await this.bridge.create({ type: "mixing" });
} catch (error) {
console.error(error);
this.close();
}
this.bridge.on('BridgeDestroyed', (event) => {
this.close();
});
/*
* Create the local channel. This actually creates 2
* back to back channels, one that's controlled by ARI/Stasis
* that we can put into the bridge we created above and
* another one the one that dials a phone, confbridge, etc.
* and joins _that_ bridge.
*
* localChannel below is actually the first channel.
*/
this.localChannel = this.ari.Channel();
this.localChannel.on('StasisStart', (event, chan) => {
this.bridge.addChannel({ channel: chan.id });
});
this.localChannel.on('StasisEnd', (event, chan) => {
this.close();
});
// Call the phone or confbridge specified in dialstring
try {
await this.localChannel.originate({
endpoint: this.options.dialstring, formats: this.options.format, app: "externalMedia",
});
} catch (error) {
this.close();
}
// Now we create the External Media channel.
this.externalChannel = this.ari.Channel();
this.externalChannel.on('StasisStart', (event, chan) => {
this.bridge.addChannel({ channel: chan.id });
});
this.externalChannel.on('StasisEnd', (event, chan) => {
this.close();
});
/*
* We give the external channel the address of the listener
* we already set up and the format it should stream in.
*/
try {
let resp = await this.externalChannel.externalMedia({
app: "externalMedia",
external_host: this.options.listenServer,
format: this.options.format
});
this.emit('ready');
} catch (error) {
this.close();
}
}
}
module.exports.AriController = AriController;