From fc9401f04a3aca5abb22f87ebc210de8afe11d32 Mon Sep 17 00:00:00 2001 From: marvin-borner@live.com Date: Tue, 10 Apr 2018 21:50:16 +0200 Subject: Initial Commit --- .../php/vendor/cboden/ratchet/src/Ratchet/App.php | 145 +++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 assets/php/vendor/cboden/ratchet/src/Ratchet/App.php (limited to 'assets/php/vendor/cboden/ratchet/src/Ratchet/App.php') diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/App.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/App.php new file mode 100644 index 0000000..f378534 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/App.php @@ -0,0 +1,145 @@ +httpHost = $httpHost; + $this->port = $port; + + $socket = new Reactor($address . ':' . $port, $loop); + + $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); + + if (80 == $port) { + $flashUri = '0.0.0.0:843'; + } else { + $flashUri = 8843; + } + $flashSock = new Reactor($flashUri, $loop); + $this->flashServer = new IoServer($policy, $flashSock); + } + + /** + * Add an endpoint/application to the server + * @param string $path The URI the client will connect to + * @param ComponentInterface $controller Your application to server for the route. If not specified, assumed to be for a WebSocket + * @param array $allowedOrigins An array of hosts allowed to connect (same host by default), ['*'] for any + * @param string $httpHost Override the $httpHost variable provided in the __construct + * @return ComponentInterface|WsServer + */ + public function route($path, ComponentInterface $controller, array $allowedOrigins = array(), $httpHost = null) { + if ($controller instanceof HttpServerInterface || $controller instanceof WsServer) { + $decorated = $controller; + } elseif ($controller instanceof WampServerInterface) { + $decorated = new WsServer(new WampServer($controller)); + $decorated->enableKeepAlive($this->_server->loop); + } elseif ($controller instanceof MessageComponentInterface) { + $decorated = new WsServer($controller); + $decorated->enableKeepAlive($this->_server->loop); + } else { + $decorated = $controller; + } + + if ($httpHost === null) { + $httpHost = $this->httpHost; + } + + $allowedOrigins = array_values($allowedOrigins); + if (0 === count($allowedOrigins)) { + $allowedOrigins[] = $httpHost; + } + if ('*' !== $allowedOrigins[0]) { + $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, array(), array('GET'))); + + return $decorated; + } + + /** + * Run the server by entering the event loop + */ + public function run() { + $this->_server->run(); + } +} -- cgit v1.2.3