1 | 2 | simandl | <?php |
2 | | | |
3 | | | namespace Phem\Libraries\MessageBus; |
4 | | | |
5 | | | use React\EventLoop\LoopInterface; |
6 | | | use React\Socket\ConnectionInterface; |
7 | | | use React\Socket\Server; |
8 | | | |
9 | | | /** |
10 | | | * @author Jakub PetrĹžĂlka <petrzilka@czweb.net> |
11 | | | */ |
12 | | | class ReactSocketPuller extends WebsocketPuller |
13 | | | { |
14 | | | |
15 | | | protected $msgBus; |
16 | | | protected $server; |
17 | | | |
18 | | | public function __construct(LoopInterface $loop, MessageBus $msgBus) |
19 | | | { |
20 | | | $this->msgBus = $msgBus; |
21 | | | $this->server = new Server($loop); |
22 | | | $this->server->on("connection", array($this, 'onConnection')); |
23 | | | } |
24 | | | |
25 | | | public function onConnection(ConnectionInterface $conn) |
26 | | | { |
27 | | | $conn->on("data", function($data){ |
28 | | | $this->msgBus->onNotify($data); |
29 | | | }); |
30 | | | } |
31 | | | |
32 | | | public function listen($ip, $port) |
33 | | | { |
34 | | | $this->server->listen($port, $ip); |
35 | | | } |
36 | | | |
37 | | | } |