add port property to App
allow origins in flash policy server dont start a flash policy server if one is already running better CURIE support on CALL URI should be un prefixed WampConnection callResult should allow an object to be encoded and sent
This commit is contained in:
parent
6c0d0178b7
commit
72b1a44e38
12
.gitignore
vendored
12
.gitignore
vendored
@ -1,5 +1,7 @@
|
|||||||
phpunit.xml
|
phpunit.xml
|
||||||
reports
|
reports
|
||||||
sandbox
|
sandbox
|
||||||
vendor
|
vendor
|
||||||
composer.lock
|
composer.lock
|
||||||
|
/nbproject/private/
|
||||||
|
/nbproject/
|
@ -42,6 +42,12 @@ class App {
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $httpHost;
|
protected $httpHost;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* The port the socket is listening
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $port;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
@ -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);
|
||||||
@ -81,10 +88,20 @@ class App {
|
|||||||
$flashSock = new Reactor($loop);
|
$flashSock = new Reactor($loop);
|
||||||
$this->flashServer = new IoServer($policy, $flashSock);
|
$this->flashServer = new IoServer($policy, $flashSock);
|
||||||
|
|
||||||
if (80 == $port) {
|
//check if another App is already running a flash policy server on 843
|
||||||
$flashSock->listen(843, '0.0.0.0');
|
$test = @fsockopen('127.0.0.1', 843, $errno, $errstr, 5);
|
||||||
} else {
|
|
||||||
$flashSock->listen(8843);
|
//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]) {
|
if ('*' !== $allowedOrigins[0]) {
|
||||||
$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));
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface {
|
|||||||
$json = $json[0];
|
$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;
|
break;
|
||||||
|
|
||||||
case static::MSG_SUBSCRIBE:
|
case static::MSG_SUBSCRIBE:
|
||||||
|
@ -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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
* 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
|
* @param string $uri
|
||||||
* @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);
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user