| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Console\Commands;
- use App\Services\Socket\ChatService;
- use Illuminate\Console\Command;
- use Ratchet\Http\HttpServer;
- use Ratchet\Server\IoConnection;
- use Ratchet\Server\IoServer;
- use Ratchet\WebSocket\WsConnection;
- use Ratchet\WebSocket\WsServer;
- class WebSocketServer extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'websocket:serve';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Start the WebSocket server by whatsapp';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- $server = IoServer::factory(
- new HttpServer(
- new WsServer(
- new ChatService()
- )
- ),
- 8605
- );
- $server->run();
- echo 'socket service start success';
- return 0;
- }
- }
|