Reverted the changes previously made in favor of a different approach as requested in https://github.com/cboden/Ratchet/pull/188

This commit is contained in:
Gerrit Drost 2014-05-23 16:20:27 +02:00
parent 06c4c3ddd8
commit a456c50df4

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Ratchet; namespace Ratchet;
use React\EventLoop\LoopInterface; use React\EventLoop\LoopInterface;
use React\EventLoop\Factory as LoopFactory; use React\EventLoop\Factory as LoopFactory;
use React\Socket\Server as Reactor; use React\Socket\Server as Reactor;
@ -49,16 +51,12 @@ class App {
protected $_routeCounter = 0; protected $_routeCounter = 0;
/** /**
* @param string $httpHost HTTP hostname clients intend to connect to. MUST match JS `new WebSocket('ws://$httpHost') * @param string $httpHost HTTP hostname clients intend to connect to. MUST match JS `new WebSocket('ws://$httpHost');`
* @param int $port Port to listen on * @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 $address IP address to bind to. Default is localhost/proxy only. '0.0.0.0' for any machine.
* @param array $flashAllowedHosts associative array with hostnames as key and ports as value. These domains are the domains the flash websocket fallback may connect from * @param LoopInterface $loop Specific React\EventLoop to bind the application to. null will create one for you.
* @param int $flashPort the port the flash cross-domain-policy file will be hosted on
* @param string $flashAddress the IP address the flash cross-domain-policy server will bind to
* @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', $flashAllowedHosts = false, $flashPort = 8843, $flashAddress = '0.0.0.0', 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);
} }
@ -79,20 +77,26 @@ class App {
$this->routes = new RouteCollection; $this->routes = new RouteCollection;
$this->_server = new IoServer(new HttpServer(new Router(new UrlMatcher($this->routes, new RequestContext))), $socket, $loop); $this->_server = new IoServer(new HttpServer(new Router(new UrlMatcher($this->routes, new RequestContext))), $socket, $loop);
if ($flashAllowedHosts === false) {
$flashAllowedHosts = array( 80 => $httpHost );
}
$policy = new FlashPolicy(); $policy = new FlashPolicy();
$policy->addAllowedAccess($httpHost, 80);
foreach ($flashAllowedHosts as $flashAllowedHost => $flashAllowedPort) { $policy->addAllowedAccess($httpHost, $port);
$policy->addAllowedAccess($flashAllowedHost, $flashAllowedPort);
}
$flashSock = new Reactor($loop); $flashSock = new Reactor($loop);
$this->flashServer = new IoServer($policy, $flashSock); $this->flashServer = new IoServer($policy, $flashSock);
$flashSock->listen($flashPort, $flashAddress);
if (80 == $port) {
$flashSock->listen(843, '0.0.0.0');
} else {
$flashSock->listen(8843);
}
}
/**
* Returns the FlashPolicy running in the FlashServer. Modifications of this object take effect immediately!
*
* @return FlashPolicy
*/
public function getFlashPolicy() {
return $this->flashServer->getApp();
} }
/** /**
@ -136,3 +140,4 @@ class App {
$this->_server->run(); $this->_server->run();
} }
} }