From c179d60e77a9f370d278285c95eb34464687c862 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 23 Nov 2014 11:40:06 -0500 Subject: [PATCH] Formatting, removed flash check --- src/Ratchet/App.php | 34 ++++++++++------------------- src/Ratchet/Wamp/ServerProtocol.php | 1 - src/Ratchet/Wamp/WampConnection.php | 25 ++++++++++----------- tests/unit/Wamp/TopicTest.php | 2 +- 4 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index 4755560..4e44663 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -42,12 +42,12 @@ class App { * @var string */ protected $httpHost; - + /*** * The port the socket is listening * @var int */ - protected $port; + protected $port; /** * @var int @@ -87,22 +87,10 @@ class App { $policy->addAllowedAccess($httpHost, $port); $flashSock = new Reactor($loop); $this->flashServer = new IoServer($policy, $flashSock); - - //check if another App is already running a flash policy server on 843 - $test = @fsockopen('127.0.0.1', 843, $errno, $errstr, 5); - - //if not start a flash policy serever - if(is_resource($test) === false){ - $policy = new FlashPolicy; - $policy->addAllowedAccess($httpHost, 80); - $policy->addAllowedAccess($httpHost, $port); - $flashSock = new Reactor($loop); - $this->flashServer = new IoServer($policy, $flashSock); - - $flashSock->listen(843, '0.0.0.0'); - }else{ - fclose($test); - trigger_error('flash socket server already running on 843', E_USER_NOTICE); + if (80 == $port) { + $flashSock->listen(843, '0.0.0.0'); + } else { + $flashSock->listen(8843); } } @@ -136,12 +124,12 @@ class App { if ('*' !== $allowedOrigins[0]) { $decorated = new OriginCheck($decorated, $allowedOrigins); } - + //allow origins in flash policy server - if(empty($this->flashServer) === false){ - foreach($allowedOrigins as $allowedOrgin){ - $this->flashServer->app->addAllowedAccess($allowedOrgin, $this->port); - } + if(empty($this->flashServer) === false) { + foreach($allowedOrigins as $allowedOrgin) { + $this->flashServer->app->addAllowedAccess($allowedOrgin, $this->port); + } } $this->routes->add('rr-' . ++$this->_routeCounter, new Route($path, array('_controller' => $decorated), array('Origin' => $this->httpHost), array(), $httpHost)); diff --git a/src/Ratchet/Wamp/ServerProtocol.php b/src/Ratchet/Wamp/ServerProtocol.php index 0bddc83..28badd3 100644 --- a/src/Ratchet/Wamp/ServerProtocol.php +++ b/src/Ratchet/Wamp/ServerProtocol.php @@ -107,7 +107,6 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface { $json = $json[0]; } - //procURI should be un prefixed $this->_decorating->onCall($from, $callID, $from->getUri($procURI), $json); break; diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index 8364efd..64590a0 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -17,7 +17,7 @@ class WampConnection extends AbstractConnectionDecorator { parent::__construct($conn); $this->WAMP = new \StdClass; - $this->WAMP->sessionId = str_replace('.','',uniqid(mt_rand(), true)); + $this->WAMP->sessionId = str_replace('.', '', uniqid(mt_rand(), true)); $this->WAMP->prefixes = array(); $this->send(json_encode(array(WAMP::MSG_WELCOME, $this->WAMP->sessionId, 1, \Ratchet\VERSION))); @@ -77,24 +77,23 @@ class WampConnection extends AbstractConnectionDecorator { /** * Get the full request URI from the connection object if a prefix has been established for it - * Compliant with WAMP Spec for curie URIs * @param string $uri * @return string */ public function getUri($uri) { - $curieSeperator = ':'; - $fullSeperator = '#'; - - if(preg_match('/http(s*)\:\/\//', $uri) == false){ - if(strpos($uri, $curieSeperator) !== false){ - list($prefix, $action) = explode($curieSeperator, $uri); - $expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix; + $curieSeperator = ':'; + $fullSeperator = '#'; - return $expandedPrefix . $fullSeperator . $action; + if (preg_match('/http(s*)\:\/\//', $uri) == false) { + if (strpos($uri, $curieSeperator) !== false) { + list($prefix, $action) = explode($curieSeperator, $uri); + $expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix; + + return $expandedPrefix . $fullSeperator . $action; + } } - } - - return $uri; + + return $uri; } /** diff --git a/tests/unit/Wamp/TopicTest.php b/tests/unit/Wamp/TopicTest.php index 26db0d3..b8685b7 100644 --- a/tests/unit/Wamp/TopicTest.php +++ b/tests/unit/Wamp/TopicTest.php @@ -81,7 +81,7 @@ class TopicTest extends \PHPUnit_Framework_TestCase { $topic->add($first); $topic->add($second); $topic->add($third); - + $topic->broadcast($msg, array($second->WAMP->sessionId)); }