Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
<?php
/**
 * Created by PhpStorm.
 * User: danilo
 * Date: 27/07/16
 * Time: 10:40
 */

namespace Modules\Core\Commands\Socket;

use Config;
use Illuminate\Console\Command;
use Modules\Core\Services\SocketRouter;
use Ratchet\App as Socket;

class Server extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'socket:serve';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Start web socket server.';

    /**
     * $httpHost HTTP hostname clients intend to connect to.
     * MUST match JS `new WebSocket('ws://$httpHost').
     */
    protected $httpHost;

    /**
     * Port to listen on. If 80, assuming production,
     * Flash on 843 otherwise expecting Flash to be proxied through 8843.
     */
    protected $port;

    /**
     *IP address to bind to. Default is localhost/proxy only.
     *'0.0.0.0' for any machine.
     */
    protected $address;

    /**
     * Create a new command instance.
     */
    public function __construct()
    {
        $config = Config::get('socket');
        $this->httpHost = $config['httpHost'];
        $this->port = $config['port'];
        $this->address = $config['address'];
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire(SocketRouter $router)
    {
        $socket = new Socket($this->httpHost, $this->port, $this->address);
        //require_once app_path() . '/Http/Socket/routes.php';
        $router->execute($socket);
        $this->info('Laravel web socket server started on ' . $this->httpHost . ':' . $this->port . '/' . 'address:' . $this->address);
        $socket->run();
    }
}