Exemplo n.º 1
0
 public function testCollectingSIPEvents()
 {
     $client = $this->createClientMock();
     // expect a single outgoing action request (and mock its ID)
     $client->expects($this->once())->method('createAction')->with($this->equalTo('SIPPeers'), $this->equalTo(array()))->will($this->returnValue(new Action(array('Action' => 'SIPPeers', 'ActionID' => '123'))));
     $collector = new Collector($client);
     $promise = $collector->sipPeers();
     // save resolved result for comparisions
     $resolved = null;
     $promise->then(function ($result) use(&$resolved) {
         $resolved = $result;
     });
     // should not start out resolved
     $this->assertNull($resolved);
     $response = new Response(array('Response' => 'Success', 'ActionID' => '123'));
     $client->handleMessage($response);
     $client->handleMessage(new Event(array('Event' => 'PeerEntry', 'ActionID' => '123')));
     $client->handleMessage(new Event(array('Event' => 'PeerEntry', 'ActionID' => '123')));
     $this->assertNull($resolved);
     $client->handleMessage(new Event(array('Event' => 'PeerlistComplete', 'EventList' => 'complete', 'ListItems' => '2', 'ActionID' => '123')));
     $this->assertNotNull($resolved);
     $promise->then($this->expectCallableOnce());
 }
Exemplo n.º 2
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();