Exemple #1
0
 public function testConnection()
 {
     $factory = new Factory(self::$loop);
     $client = $this->waitFor($factory->createClient(self::$address));
     /* @var $client Client */
     $this->assertFalse($client->isBusy());
     return $client;
 }
Exemple #2
0
 /**
  * Connect to AMI and start emitting events.
  *
  * @param string $address Example uaername:password@localhost:5038
  * @return \React\Promise\Promise
  */
 public function connect($address)
 {
     $factory = new Factory($this->eventLoop);
     return $factory->createClient($address)->then(function (Client $client) {
         $this->amiClient = $client;
         $this->actionSender = new ActionSender($client);
         $this->actionSender->events(true);
         $client->on('close', function () {
             $this->logger->debug('AMI connection closed');
         });
         $client->on('event', function (Event $event) {
             $this->wsClient->emit($event->getName(), (array) $event);
         });
     }, function (\Exception $e) {
         $this->logger->err('Connection error: ' . $e->getMessage());
     });
 }
Exemple #3
0
<?php

use Clue\React\Ami\Factory;
use Clue\React\Ami\Client;
use Clue\React\Ami\ActionSender;
use Clue\React\Ami\Collector;
use Clue\React\Ami\Protocol\Collection;
require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$factory = new Factory($loop);
$target = isset($argv[1]) ? $argv[1] : 'name:password@localhost';
$factory->createClient($target)->then(function (Client $client) use($loop) {
    echo 'Successfully connected' . PHP_EOL;
    $collector = new Collector($client);
    $collector->sipPeers()->then(function (Collection $collection) {
        var_dump('result', $collection);
        $peers = $collection->getEntryEvents();
        echo 'found ' . count($peers) . ' peers' . PHP_EOL;
    });
}, 'var_dump');
$loop->run();