Exemple #1
0
 public function broadcast($msg)
 {
     foreach ($this->clients as $client) {
         $client->send($msg);
         Log::v('S', $client, "sending message \"{$msg}\"");
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $port = intval($this->option('port'));
     $loop = \React\EventLoop\Factory::create();
     $pusher = new \App\Websocket\Pusher($loop);
     $webSock = new \React\Socket\Server($loop);
     $webSock->listen($port, '0.0.0.0');
     $webServer = new \Ratchet\Server\IoServer(new \Ratchet\Http\HttpServer(new \Ratchet\WebSocket\WsServer(new \App\Websocket\Chat($pusher))), $webSock);
     \App\Websocket\Log::v(' ', $loop, "Starting Websocket Service on port " . $port);
     $loop->run();
 }
Exemple #3
0
 public function __construct($loop)
 {
     $redis_host = config('database.redis.default.host');
     $redis_port = config('database.redis.default.port');
     $client = new \Predis\Async\Client('tcp://' . $redis_host . ':' . $redis_port, $loop);
     $client->connect(function ($client) use($loop) {
         // $logger = new \Predis\Async\Client('tcp://127.0.0.1:6379', $loop);
         $logger = null;
         $client->pubSubLoop('WampMessage', function ($event) use($logger) {
             $payload = json_decode($event->payload, true);
             Chat::getInstance()->broadcast($payload['data']);
         });
         Log::v(' ', $loop, "Connected to Redis.");
     });
 }