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(); $routes = WebSocketRouter::getRoutes();
/** 🎩 Start the magic 🎩 */ /** 🎩 Start the magic 🎩 */
(new WebSocketServerFactory($routes)) (new WebSocketServerFactory())
->useRoutes($routes)
->setHost($this->option('host')) ->setHost($this->option('host'))
->setPort($this->option('port')) ->setPort($this->option('port'))
->setConsoleOutput($this->output) ->setConsoleOutput($this->output)
->createServer()
->run(); ->run();
} }
} }

View File

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