22
33namespace Socks ;
44
5+ use Evenement \EventEmitter ;
6+ use React \Socket \ServerInterface ;
57use React \Promise \When ;
68use React \Promise \PromiseInterface ;
79use React \Stream \Stream ;
810use ConnectionManager \ConnectionManagerInterface ;
911use React \Socket \Connection ;
1012use React \EventLoop \LoopInterface ;
11- use React \Socket \Server as SocketServer ;
1213use \UnexpectedValueException ;
1314use \InvalidArgumentException ;
1415use \Exception ;
1516
16- class Server extends SocketServer
17+ class Server extends EventEmitter
1718{
1819 protected $ loop ;
1920
@@ -23,14 +24,16 @@ class Server extends SocketServer
2324
2425 private $ protocolVersion = null ;
2526
26- public function __construct (LoopInterface $ loop , ConnectionManagerInterface $ connectionManager )
27+ public function __construct (ServerInterface $ serverInterface , LoopInterface $ loop , ConnectionManagerInterface $ connectionManager )
2728 {
28- parent ::__construct ($ loop );
29-
3029 $ this ->loop = $ loop ;
3130 $ this ->connectionManager = $ connectionManager ;
3231
33- $ this ->on ('connection ' , array ($ this , 'onConnection ' ));
32+ $ that = $ this ;
33+ $ serverInterface ->on ('connection ' , function ($ connection ) use ($ that ) {
34+ $ that ->emit ('connection ' , array ($ connection ));
35+ $ that ->onConnection ($ connection );
36+ });
3437 }
3538
3639 public function setProtocolVersion ($ version )
@@ -79,10 +82,7 @@ public function unsetAuth()
7982
8083 public function onConnection (Connection $ connection )
8184 {
82- // $this->emit('connection', array($connection));
83-
8485 $ that = $ this ;
85- $ loop = $ this ->loop ;
8686 $ this ->handleSocks ($ connection )->then (function ($ remote ) use ($ connection ){
8787 $ connection ->emit ('ready ' ,array ($ remote ));
8888 }, function ($ error ) use ($ connection , $ that ) {
0 commit comments