@@ -79,8 +79,7 @@ Once [installed](#install), you can use the following code to access your local
7979Asterisk instance and issue some simple commands via AMI:
8080
8181``` php
82- $loop = React\EventLoop\Factory::create();
83- $factory = new Clue\React\Ami\Factory($loop);
82+ $factory = new Clue\React\Ami\Factory();
8483
8584$factory->createClient('user:secret@localhost')->then(function (Clue\React\Ami\Client $client) {
8685 echo 'Client connected' . PHP_EOL;
@@ -91,8 +90,6 @@ $factory->createClient('user:secret@localhost')->then(function (Clue\React\Ami\C
9190 var_dump($response);
9291 });
9392});
94-
95- $loop->run();
9693```
9794
9895See also the [ examples] ( examples ) .
@@ -102,19 +99,23 @@ See also the [examples](examples).
10299### Factory
103100
104101The ` Factory ` is responsible for creating your [ ` Client ` ] ( #client ) instance.
105- It also registers everything with the main [ ` EventLoop ` ] ( https://github.com/reactphp/event-loop#usage ) .
106102
107103``` php
108- $loop = React\EventLoop\Factory::create();
109- $factory = new Clue\React\Ami\Factory($loop);
104+ $factory = new Clue\React\Ami\Factory();
110105```
111106
107+ This class takes an optional ` LoopInterface|null $loop ` parameter that can be used to
108+ pass the event loop instance to use for this object. You can use a ` null ` value
109+ here in order to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
110+ This value SHOULD NOT be given unless you're sure you want to explicitly use a
111+ given event loop instance.
112+
112113If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
113114proxy servers etc.), you can explicitly pass a custom instance of the
114115[ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface ) :
115116
116117``` php
117- $connector = new React\Socket\Connector($loop , array(
118+ $connector = new React\Socket\Connector(null , array(
118119 'dns' => '127.0.0.1',
119120 'tcp' => array(
120121 'bindto' => '192.168.10.1:0'
@@ -125,7 +126,7 @@ $connector = new React\Socket\Connector($loop, array(
125126 )
126127));
127128
128- $factory = new Clue\React\Ami\Factory($loop , $connector);
129+ $factory = new Clue\React\Ami\Factory(null , $connector);
129130```
130131
131132#### createClient()
@@ -374,11 +375,11 @@ The resulting blocking code could look something like this:
374375
375376``` php
376377use Clue\React\Block;
378+ use React\EventLoop\Loop;
377379
378380function getSipPeers()
379381{
380- $loop = React\EventLoop\Factory::create();
381- $factory = new Clue\React\Ami\Factory($loop);
382+ $factory = new Clue\React\Ami\Factory();
382383
383384 $target = 'name:password@localhost';
384385 $promise = $factory->createClient($target)->then(function (Clue\React\Ami\Client $client) {
@@ -390,7 +391,7 @@ function getSipPeers()
390391 return $ret;
391392 });
392393
393- return Block\await($promise, $loop , 5.0);
394+ return Block\await($promise, Loop::get() , 5.0);
394395}
395396```
396397
0 commit comments