Merge branch 'master' of github.com:beyondcode/laravel-websockets

This commit is contained in:
Marcel Pociot 2018-11-27 21:56:33 +01:00
commit 2a911d6706
2 changed files with 10 additions and 10 deletions

View File

@ -74,10 +74,12 @@ class StartWebSocketServer extends Command
$routes = WebSocketRouter::getRoutes();
/** 🎩 Start the magic 🎩 */
(new WebSocketServerFactory($routes))
(new WebSocketServerFactory())
->useRoutes($routes)
->setHost($this->option('host'))
->setPort($this->option('port'))
->setConsoleOutput($this->output)
->createServer()
->run();
}
}

View File

@ -31,11 +31,16 @@ class WebSocketServerFactory
/** @var Symfony\Component\Console\Output\OutputInterface */
protected $consoleOutput;
public function __construct(RouteCollection $routes)
public function __construct()
{
$this->loop = LoopFactory::create();
}
public function useRoutes(RouteCollection $routes)
{
$this->routes = $routes;
return $this;
}
public function setHost(string $host)
@ -66,14 +71,7 @@ class WebSocketServerFactory
return $this;
}
public function run()
{
$server = $this->createServer();
$server->run();
}
protected function createServer(): IoServer
public function createServer(): IoServer
{
$socket = new Server("{$this->host}:{$this->port}", $this->loop);