0 purchases
dart ari proxy
Dart-ari-proxy: Asterisk Rest Interface in Dart #
ari-Dart-examples #
This project includes Dart versions of the examples published on project https://github.com/asterisk/node-ari-client for
the Asterisk REST Interface. It uses the Dart definitions @types/ari-client for the ari-client Node.js module.
The purpose of the @types/ari-client definitions and these examples is to facilitate the development of applications based on ARI.
Configuration #
Before running any example or tests, you have to create a .env file at the root of the project and set the
URL and credentials of the development Asterisk box you want to connect to.
ARI_URL=http://127.0.0.1:8888/ari
ARI_USERNAME=username
ARI_PASSWORD=password
copied to clipboard
These parameters can be easily retrieved by importing src/config.ts:
import { url, username, password } from "./config";
copied to clipboard
Note: in order to setup your Asterisk to use ARI, follow the instructions in https://wiki.asterisk.org/wiki/display/AST/Asterisk+Configuration+for+ARI.
Running Examples #
Examples in folder src/examples are divided into callbacks and promises. The callbacks folder contains the Dart versions of
the examples published on https://github.com/asterisk/node-ari-client using callback functions. The promises folder contains the
Dart version of the same examples, but using promises and async/await syntax.
examples
├── callbacks # Examples using callback functions.
│ ├── bridge.ts
│ ├── deviceState.ts
│ ├── example.ts
│ ├── mwi.ts
│ ├── originate.ts
│ └── playback.ts
└── promises # Examples using promises with async/await syntax.
├── bridge.ts
├── deviceState.ts
├── example.ts
├── mwi.ts
├── originate.ts
└── playback.ts
copied to clipboard
You can run any of these examples by executing the command:
yarn run dev example-file [promises/callbacks]
copied to clipboard
Just replace "example-file" with the name of the example file you want to run (bridge, mwi, etc.), followed by the corresponding
version (promises or callbacks). By default promises versions are run.
If you want to run the callbacks version of the bridge example, execute:
yarn run dev bridge callbacks
copied to clipboard
If you want to run the promises version of the originate example, execute:
yarn run dev originate
copied to clipboard
Debugging #
The examples use the debug module, so you can just add debug() wherever you want to see what is happening.
Be sure to add DEBUG=* to your .env file.
ARI_URL=http://127.0.0.1:8888/ari
ARI_USERNAME=username
ARI_PASSWORD=password
DEBUG=*
copied to clipboard
@types/ari-client #
This project uses Dart definitions @types/ari-client for the ari-client Node.js module.
Using these definitions you can import in Dart resources from the library as follows.
import Ari, { Channel, Bridge } from 'ari-client';
copied to clipboard
Note: you have to turn on esModuleInterop option in tsconfig.json in order to destructured import Asterisk objects (Channel, Bridge, Endpoint, etc.).
Default module export exposes the connect() function, so you can connect to an Asterisk instance as follows:
// Using promises (async/await).
const client = await Ari.connect(url, username, password);
console.log(`Now connected to ${url}`);
// Using a callback function.
Ari.connect(url, username, password, (err, client) => {
console.log(`Now connected to ${url}`);
});
copied to clipboard
Running Test #
You can also run a series of tests against the Asterisk instance defined in .env file as follows:
yarn run test
copied to clipboard
IMPORTANT: Do not run these tests against a production Asterisk box.
If you receive warnings like the following when running tests, it is because the corresponding Asterisk primitive object list is empty.
console.warn
No channels found to check Channel object.
copied to clipboard
You can find in src/fixtures folder the ARI resource files of an Asterisk 16.9. As explained in node-ari-client
documentation (https://github.com/asterisk/node-ari-client/blob/master/README.md), fixtures for ARI resources can be
generated from a local Asterisk instance by running the following:
$ grunt genfixtures
copied to clipboard
These files are only used during tests to verify that objects received from the Asterisk box have the expected properties.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.