diff --git a/.gitignore b/.gitignore index 2e580df..32db066 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ -phpunit.xml -reports -sandbox -vendor -composer.lock +phpunit.xml +reports +sandbox +vendor +composer.lock +/nbproject/private/ +/nbproject/ \ No newline at end of file diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index c6d9ceb..f7d5e52 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -42,6 +42,12 @@ class App { * @var string */ protected $httpHost; + + /*** + * The port the socket is listening + * @var int + */ + protected $port; /** * @var int @@ -68,6 +74,7 @@ class App { } $this->httpHost = $httpHost; + $this->port = $port; $socket = new Reactor($loop); $socket->listen($port, $address); @@ -81,10 +88,20 @@ class App { $flashSock = new Reactor($loop); $this->flashServer = new IoServer($policy, $flashSock); - if (80 == $port) { - $flashSock->listen(843, '0.0.0.0'); - } else { - $flashSock->listen(8843); + //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); } } @@ -118,6 +135,13 @@ 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); + } + } $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 92dbd85..0bddc83 100644 --- a/src/Ratchet/Wamp/ServerProtocol.php +++ b/src/Ratchet/Wamp/ServerProtocol.php @@ -107,7 +107,8 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface { $json = $json[0]; } - $this->_decorating->onCall($from, $callID, $procURI, $json); + //procURI should be un prefixed + $this->_decorating->onCall($from, $callID, $from->getUri($procURI), $json); break; case static::MSG_SUBSCRIBE: diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index 95e1969..6e46eba 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -26,10 +26,10 @@ class WampConnection extends AbstractConnectionDecorator { /** * Successfully respond to a call made by the client * @param string $id The unique ID given by the client to respond to - * @param array $data An array of data to return to the client + * @param array $data an object or array * @return WampConnection */ - public function callResult($id, array $data = array()) { + public function callResult($id, $data = array()) { return $this->send(json_encode(array(WAMP::MSG_CALL_RESULT, $id, $data))); } @@ -77,11 +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) { - return (array_key_exists($uri, $this->WAMP->prefixes) ? $this->WAMP->prefixes[$uri] : $uri); + $seperator = ':'; + + if(preg_match('/http(s*)\:\/\//', $uri) === false){ + if(strpos($uri, $seperator) !== false){ + list($prefix, $action) = explode(':', $uri); + $expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix; + + return $expandedPrefix . '#' . $action; + } + } + + return $uri; } /**