laravel-websockets/src/Console/StartWebSocketServer.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2018-11-20 10:51:00 +00:00
<?php
2018-11-21 11:13:40 +00:00
namespace BeyondCode\LaravelWebSockets\Console;
2018-11-20 10:51:00 +00:00
2018-11-21 20:23:25 +00:00
use BeyondCode\LaravelWebSockets\Facades\WebSocketRouter;
2018-11-20 10:51:00 +00:00
use Illuminate\Console\Command;
use BeyondCode\LaravelWebSockets\Server\WebSocketServer;
use React\EventLoop\Factory as LoopFactory;
class StartWebSocketServer extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'websocket:start {--port=6001}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Start the Laravel WebSocket Server';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$loop = LoopFactory::create();
2018-11-21 20:23:25 +00:00
$loop->futureTick(function () {
2018-11-20 10:51:00 +00:00
$this->info('Started the WebSocket server on port '.$this->option('port'));
});
2018-11-21 20:23:25 +00:00
// TODO: add an option to not start the echo server
WebSocketRouter::echo();
2018-11-21 22:47:46 +00:00
// TODO: add flag for verbose mode, to send more things to console
2018-11-21 20:23:25 +00:00
(new WebsocketServer($this->option('port'), '0.0.0.0', $loop))->run();
2018-11-20 10:51:00 +00:00
}
}