1. Go to this page and download the library: Download clue/ami-react library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$factory->createClient($url)->then(
function (Clue\React\Ami\Client $client) {
// client connected (and authenticated)
},
function (Exception $e) {
// an error occurred while trying to connect or authorize client
}
);
$client->on('event', function (Clue\React\Ami\Protocol\Event $event) {
// process an incoming AMI event (see below)
var_dump($event->getName(), $event);
});
$sender->ping()->then(
function (Clue\React\Ami\Protocol\Response $response) {
// response received for ping action
},
function (Exception $e) {
// an error occurred while executing the action
if ($e instanceof Clue\React\Ami\Protocol\ErrorException) {
// we received a valid error response (such as authorization error)
$response = $e->getResponse();
} else {
// we did not receive a valid response (likely a transport issue)
}
}
});
use Clue\React\Block;
use React\EventLoop\Loop;
function getSipPeers()
{
$factory = new Clue\React\Ami\Factory();
$target = 'name:password@localhost';
$promise = $factory->createClient($target)->then(function (Clue\React\Ami\Client $client) {
$sender = new Clue\React\Ami\ActionSender($client);
$ret = $sender->sipPeers()->then(function (Clue\React\Ami\Collection $collection) {
return $collection->getEntryEvents();
});
$client->end();
return $ret;
});
return Block\await($promise, Loop::get(), 5.0);
}