In my laravel 5.7 app I installed cboden/ratchet using some online docs
composer.json :
"type": "project",
"require": {
...
"cboden/ratchet": "^0.4.1",
With app/Classes/Socket/Base/BaseSocket.php :
<?php
namespace App\Classes\Socket\Base;
use Rachet\MessageComponentInterface;
use Rachet\ConnectionInterface;
class BaseSocket implements MessageComponentInterface {
public function onOpen(ConnectionInterface $conn) {
}
public function onMessage(ConnectionInterface $conn, $mgs) {
}
public function onClose(ConnectionInterface $conn) {
}
public function onError(ConnectionInterface $conn, \Exception $e) {
}
}
and console command app/Console/Commands/ChatServer.php :
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;
use App\Classes\Socket\ChatSocket;
class ChatServer extends Command
{
protected $signature = 'chat_server:serve';
protected $description = 'chat_server description';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->info("Start server!");
$server= IoServer::factory(
new HttpServer(
new WsServer(
new ChatSocket()
)
),
8080
);
$server->run();
}
}
But running command in console I got error:
$ php artisan chat_server:serve
Start server!
PHP Fatal error: Interface 'Rachet\MessageComponentInterface' not found in /mnt/_work_sdb8/wwwroot/lar/Votes/app/Classes/Socket/Base/BaseSocket.php on line 7
Symfony\Component\Debug\Exception\FatalErrorException : Interface 'Rachet\MessageComponentInterface' not found
at /mnt/_work_sdb8/wwwroot/lar/Votes/app/Classes/Socket/Base/BaseSocket.php:7
3|
4| use Rachet\MessageComponentInterface;
5| use Rachet\ConnectionInterface;
6|
> 7| class BaseSocket implements MessageComponentInterface {
8|
9| public function onOpen(ConnectionInterface $conn) {
10|
11| }
Whoops\Exception\ErrorException : Interface 'Rachet\MessageComponentInterface' not found
at /mnt/_work_sdb8/wwwroot/lar/Votes/app/Classes/Socket/Base/BaseSocket.php:7
3|
4| use Rachet\MessageComponentInterface;
5| use Rachet\ConnectionInterface;
6|
> 7| class BaseSocket implements MessageComponentInterface {
8|
9| public function onOpen(ConnectionInterface $conn) {
10|
11| }
Did I miss some declarations or have I to add declarations to app.php ? Reading docs I missed if I have add config declarations?
UPDATED BLOCK # 2:
Searching for decision I found an opinion, that I need to create my own service provider for it register it properly in Laravel Which steps have I to do to create my own service provider for "cboden/ratchet" ? This is out of my laravel expierence...
Thanks!
Looks like misspelling. Must be :
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;