host = $host; $this->port = $port; $this->loop = LoopFactory::create(); } /** * Add the routes. * * @param \Symfony\Component\Routing\RouteCollection $routes * @return $this */ public function useRoutes(RouteCollection $routes) { $this->routes = $routes; return $this; } /** * Set the loop instance. * * @param \React\EventLoop\LoopInterface $loop * @return $this */ public function setLoop(LoopInterface $loop) { $this->loop = $loop; return $this; } /** * Set the console output. * * @param \Symfony\Component\Console\Output\OutputInterface $consoleOutput * @return $this */ public function setConsoleOutput(OutputInterface $consoleOutput) { $this->consoleOutput = $consoleOutput; return $this; } /** * Set up the server. * * @return \Ratchet\Server\IoServer */ public function createServer(): IoServer { $socket = new Server("{$this->host}:{$this->port}", $this->loop); if (config('websockets.ssl.local_cert')) { $socket = new SecureServer($socket, $this->loop, config('websockets.ssl')); } $app = new Router( new UrlMatcher($this->routes, new RequestContext) ); $httpServer = new HttpServer($app, config('websockets.max_request_size_in_kb') * 1024); if (HttpLogger::isEnabled()) { $httpServer = HttpLogger::decorate($httpServer); } return new IoServer($httpServer, $socket, $this->loop); } }