diff --git a/.gitignore b/.gitignore index 2e580df..793ef58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -phpunit.xml -reports -sandbox -vendor -composer.lock +phpunit.xml +reports +sandbox +vendor +composer.lock \ No newline at end of file diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index c6d9ceb..4e44663 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -43,6 +43,12 @@ class App { */ protected $httpHost; + /*** + * The port the socket is listening + * @var int + */ + protected $port; + /** * @var int */ @@ -56,7 +62,7 @@ class App { */ public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null) { if (extension_loaded('xdebug')) { - trigger_error("XDebug extension detected. Remember to disable this if performance testing or going live!", E_USER_WARNING); + trigger_error('XDebug extension detected. Remember to disable this if performance testing or going live!', E_USER_WARNING); } if (3 !== strlen('✓')) { @@ -68,6 +74,7 @@ class App { } $this->httpHost = $httpHost; + $this->port = $port; $socket = new Reactor($loop); $socket->listen($port, $address); @@ -80,7 +87,6 @@ class App { $policy->addAllowedAccess($httpHost, $port); $flashSock = new Reactor($loop); $this->flashServer = new IoServer($policy, $flashSock); - if (80 == $port) { $flashSock->listen(843, '0.0.0.0'); } else { @@ -119,6 +125,13 @@ class App { $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)); return $decorated; diff --git a/src/Ratchet/Wamp/ServerProtocol.php b/src/Ratchet/Wamp/ServerProtocol.php index 92dbd85..28badd3 100644 --- a/src/Ratchet/Wamp/ServerProtocol.php +++ b/src/Ratchet/Wamp/ServerProtocol.php @@ -107,7 +107,7 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface { $json = $json[0]; } - $this->_decorating->onCall($from, $callID, $procURI, $json); + $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..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 = uniqid(); + $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))); @@ -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))); } @@ -81,7 +81,19 @@ class WampConnection extends AbstractConnectionDecorator { * @return string */ public function getUri($uri) { - return (array_key_exists($uri, $this->WAMP->prefixes) ? $this->WAMP->prefixes[$uri] : $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; + + return $expandedPrefix . $fullSeperator . $action; + } + } + + return $uri; } /** diff --git a/tests/unit/Wamp/ServerProtocolTest.php b/tests/unit/Wamp/ServerProtocolTest.php index 1b423d2..082a3f5 100644 --- a/tests/unit/Wamp/ServerProtocolTest.php +++ b/tests/unit/Wamp/ServerProtocolTest.php @@ -211,13 +211,14 @@ class ServerProtocolTest extends \PHPUnit_Framework_TestCase { $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); - $shortIn = 'incoming'; - $longIn = 'http://example.com/incoming/'; + $prefix = 'incoming'; + $fullURI = "http://example.com/$prefix"; + $method = 'call'; - $this->_comp->onMessage($conn, json_encode(array(1, $shortIn, $longIn))); + $this->_comp->onMessage($conn, json_encode(array(1, $prefix, $fullURI))); - $this->assertEquals($longIn, $conn->WAMP->prefixes[$shortIn]); - $this->assertEquals($longIn, $conn->getUri($shortIn)); + $this->assertEquals($fullURI, $conn->WAMP->prefixes[$prefix]); + $this->assertEquals("$fullURI#$method", $conn->getUri("$prefix:$method")); } public function testMessageMustBeJson() {