From 9b38d863b8dbac73298a9e495677f71598d600c7 Mon Sep 17 00:00:00 2001 From: Gerrit Drost Date: Mon, 14 Apr 2014 17:24:36 +0200 Subject: [PATCH] Fix app for flash usage --- src/Ratchet/App.php | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index da634af..7cb4363 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -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); } /**