Merge branch 'benconnito'
This commit is contained in:
commit
99285acca0
@ -43,6 +43,12 @@ class App {
|
|||||||
*/
|
*/
|
||||||
protected $httpHost;
|
protected $httpHost;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* The port the socket is listening
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $port;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
@ -56,7 +62,7 @@ class App {
|
|||||||
*/
|
*/
|
||||||
public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null) {
|
public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null) {
|
||||||
if (extension_loaded('xdebug')) {
|
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('✓')) {
|
if (3 !== strlen('✓')) {
|
||||||
@ -68,6 +74,7 @@ class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->httpHost = $httpHost;
|
$this->httpHost = $httpHost;
|
||||||
|
$this->port = $port;
|
||||||
|
|
||||||
$socket = new Reactor($loop);
|
$socket = new Reactor($loop);
|
||||||
$socket->listen($port, $address);
|
$socket->listen($port, $address);
|
||||||
@ -80,7 +87,6 @@ class App {
|
|||||||
$policy->addAllowedAccess($httpHost, $port);
|
$policy->addAllowedAccess($httpHost, $port);
|
||||||
$flashSock = new Reactor($loop);
|
$flashSock = new Reactor($loop);
|
||||||
$this->flashServer = new IoServer($policy, $flashSock);
|
$this->flashServer = new IoServer($policy, $flashSock);
|
||||||
|
|
||||||
if (80 == $port) {
|
if (80 == $port) {
|
||||||
$flashSock->listen(843, '0.0.0.0');
|
$flashSock->listen(843, '0.0.0.0');
|
||||||
} else {
|
} else {
|
||||||
@ -119,6 +125,13 @@ class App {
|
|||||||
$decorated = new OriginCheck($decorated, $allowedOrigins);
|
$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));
|
$this->routes->add('rr-' . ++$this->_routeCounter, new Route($path, array('_controller' => $decorated), array('Origin' => $this->httpHost), array(), $httpHost));
|
||||||
|
|
||||||
return $decorated;
|
return $decorated;
|
||||||
|
@ -107,7 +107,7 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface {
|
|||||||
$json = $json[0];
|
$json = $json[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_decorating->onCall($from, $callID, $procURI, $json);
|
$this->_decorating->onCall($from, $callID, $from->getUri($procURI), $json);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case static::MSG_SUBSCRIBE:
|
case static::MSG_SUBSCRIBE:
|
||||||
|
@ -17,7 +17,7 @@ class WampConnection extends AbstractConnectionDecorator {
|
|||||||
parent::__construct($conn);
|
parent::__construct($conn);
|
||||||
|
|
||||||
$this->WAMP = new \StdClass;
|
$this->WAMP = new \StdClass;
|
||||||
$this->WAMP->sessionId = uniqid();
|
$this->WAMP->sessionId = str_replace('.', '', uniqid(mt_rand(), true));
|
||||||
$this->WAMP->prefixes = array();
|
$this->WAMP->prefixes = array();
|
||||||
|
|
||||||
$this->send(json_encode(array(WAMP::MSG_WELCOME, $this->WAMP->sessionId, 1, \Ratchet\VERSION)));
|
$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
|
* Successfully respond to a call made by the client
|
||||||
* @param string $id The unique ID given by the client to respond to
|
* @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
|
* @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)));
|
return $this->send(json_encode(array(WAMP::MSG_CALL_RESULT, $id, $data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,19 @@ class WampConnection extends AbstractConnectionDecorator {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getUri($uri) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,13 +211,14 @@ class ServerProtocolTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$conn = new WampConnection($this->newConn());
|
$conn = new WampConnection($this->newConn());
|
||||||
$this->_comp->onOpen($conn);
|
$this->_comp->onOpen($conn);
|
||||||
|
|
||||||
$shortIn = 'incoming';
|
$prefix = 'incoming';
|
||||||
$longIn = 'http://example.com/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($fullURI, $conn->WAMP->prefixes[$prefix]);
|
||||||
$this->assertEquals($longIn, $conn->getUri($shortIn));
|
$this->assertEquals("$fullURI#$method", $conn->getUri("$prefix:$method"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMessageMustBeJson() {
|
public function testMessageMustBeJson() {
|
||||||
|
Loading…
Reference in New Issue
Block a user