@@ -82,8 +82,7 @@ Once [installed](#install), you can use the following code to access your local
8282Asterisk instance and issue some simple commands via AMI:
8383
8484``` php
85- $loop = React\EventLoop\Factory::create();
86- $factory = new Clue\React\Ami\Factory($loop);
85+ $factory = new Clue\React\Ami\Factory();
8786
8887$factory->createClient('user:secret@localhost')->then(function (Clue\React\Ami\Client $client) {
8988 echo 'Client connected' . PHP_EOL;
@@ -94,8 +93,6 @@ $factory->createClient('user:secret@localhost')->then(function (Clue\React\Ami\C
9493 var_dump($response);
9594 });
9695});
97-
98- $loop->run();
9996```
10097
10198See also the [ examples] ( examples ) .
@@ -105,19 +102,23 @@ See also the [examples](examples).
105102### Factory
106103
107104The ` Factory ` is responsible for creating your [ ` Client ` ] ( #client ) instance.
108- It also registers everything with the main [ ` EventLoop ` ] ( https://github.com/reactphp/event-loop#usage ) .
109105
110106``` php
111- $loop = React\EventLoop\Factory::create();
112- $factory = new Clue\React\Ami\Factory($loop);
107+ $factory = new Clue\React\Ami\Factory();
113108```
114109
110+ This class takes an optional ` LoopInterface|null $loop ` parameter that can be used to
111+ pass the event loop instance to use for this object. You can use a ` null ` value
112+ here in order to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
113+ This value SHOULD NOT be given unless you're sure you want to explicitly use a
114+ given event loop instance.
115+
115116If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
116117proxy servers etc.), you can explicitly pass a custom instance of the
117118[ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface ) :
118119
119120``` php
120- $connector = new React\Socket\Connector($loop , array(
121+ $connector = new React\Socket\Connector(null , array(
121122 'dns' => '127.0.0.1',
122123 'tcp' => array(
123124 'bindto' => '192.168.10.1:0'
@@ -128,7 +129,7 @@ $connector = new React\Socket\Connector($loop, array(
128129 )
129130));
130131
131- $factory = new Clue\React\Ami\Factory($loop , $connector);
132+ $factory = new Clue\React\Ami\Factory(null , $connector);
132133```
133134
134135#### createClient()
@@ -377,11 +378,11 @@ The resulting blocking code could look something like this:
377378
378379``` php
379380use Clue\React\Block;
381+ use React\EventLoop\Loop;
380382
381383function getSipPeers()
382384{
383- $loop = React\EventLoop\Factory::create();
384- $factory = new Clue\React\Ami\Factory($loop);
385+ $factory = new Clue\React\Ami\Factory();
385386
386387 $target = 'name:password@localhost';
387388 $promise = $factory->createClient($target)->then(function (Clue\React\Ami\Client $client) {
@@ -393,7 +394,7 @@ function getSipPeers()
393394 return $ret;
394395 });
395396
396- return Block\await($promise, $loop , 5.0);
397+ return Block\await($promise, Loop::get() , 5.0);
397398}
398399```
399400
0 commit comments