Fix app for flash usage

This commit is contained in:
Gerrit Drost 2014-04-14 17:24:36 +02:00
parent 67cedf0ce6
commit 9b38d863b8

View File

@ -49,12 +49,16 @@ class App {
protected $_routeCounter = 0;
/**
* @param string $httpHost HTTP hostname clients intend to connect to. MUST match JS `new WebSocket('ws://$httpHost');`
* @param int $port Port to listen on. If 80, assuming production, Flash on 843 otherwise expecting Flash to be proxied through 8843
* @param string $address IP address to bind to. Default is localhost/proxy only. '0.0.0.0' for any machine.
* @param string $httpHost HTTP hostname clients intend to connect to. MUST match JS `new WebSocket('ws://$httpHost');`
* @param int $port Port to listen on. If 80, assuming production, Flash on 843 otherwise expecting Flash to be proxied through 8843
* @param string $address IP address to bind to. Default is localhost/proxy only. '0.0.0.0' for any machine.
* @param array $flashAllowedHosts associative array with ports as key and hostnames as value. These domains are the domains the fhlash websocket fallback may connect from
* @param int $flashPort the port the flash cross-domain-policy file will be hosted on
* @param string $flashHost the host the flash cross-domain-policy file will be hosted on
* @param LoopInterface $loop Specific React\EventLoop to bind the application to. null will create one for you.
*/
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', $flashAllowedHosts = false, $flashPort = 8843, $flashHost = '0.0.0.0', 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);
}
@ -75,17 +79,20 @@ class App {
$this->routes = new RouteCollection;
$this->_server = new IoServer(new HttpServer(new Router(new UrlMatcher($this->routes, new RequestContext))), $socket, $loop);
$policy = new FlashPolicy;
$policy->addAllowedAccess($httpHost, 80);
$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 {
$flashSock->listen(8843);
if ($flashAllowedHosts === false) {
$flashAllowedHosts = [ 80 => $httpHost ];
}
$policy = new FlashPolicy();
foreach ($flashAllowedHosts as $flashAllowedPort => $flashAllowedHost) {
$policy->addAllowedAccess($flashAllowedHost, $flashAllowedPort);
}
$flashSock = new Reactor($loop);
$this->flashServer = new IoServer($policy, $flashSock);
$flashSock->listen($flashPort, $flashHost);
}
/**