1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Command; |
4
|
|
|
|
5
|
|
|
use Ratchet\MessageComponentInterface; |
|
|
|
|
6
|
|
|
use Ratchet\ConnectionInterface; |
|
|
|
|
7
|
|
|
use Ratchet\Server\IoServer; |
|
|
|
|
8
|
|
|
use Ratchet\Http\HttpServer; |
|
|
|
|
9
|
|
|
use Ratchet\WebSocket\WsServer; |
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
13
|
|
|
|
14
|
|
|
class WebSocketServerCommand extends Command |
15
|
|
|
{ |
16
|
|
|
protected static $defaultName = 'app:websocket-server'; |
17
|
|
|
|
18
|
|
|
protected function configure() |
19
|
|
|
{ |
20
|
|
|
$this |
21
|
|
|
->setDescription('Starts the WebSocket server') |
22
|
|
|
->setHelp('This command starts a WebSocket server on port 8080'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
26
|
|
|
{ |
27
|
|
|
$output->writeln('Starting WebSocket server on port 8080...'); |
28
|
|
|
|
29
|
|
|
$server = IoServer::factory( |
30
|
|
|
new HttpServer( |
31
|
|
|
new WsServer( |
32
|
|
|
new class implements MessageComponentInterface { |
33
|
|
|
protected \SplObjectStorage $clients; |
34
|
|
|
|
35
|
|
|
public function __construct() |
36
|
|
|
{ |
37
|
|
|
$this->clients = new \SplObjectStorage(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function onOpen(ConnectionInterface $conn) |
41
|
|
|
{ |
42
|
|
|
$this->clients->attach($conn); |
43
|
|
|
echo "New connection! ({$conn->resourceId})\n"; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function onMessage(ConnectionInterface $from, $msg) |
47
|
|
|
{ |
48
|
|
|
foreach ($this->clients as $client) { |
49
|
|
|
if ($from !== $client) { |
50
|
|
|
$client->send($msg); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function onClose(ConnectionInterface $conn) |
56
|
|
|
{ |
57
|
|
|
$this->clients->detach($conn); |
58
|
|
|
echo "Connection closed! ({$conn->resourceId})\n"; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function onError(ConnectionInterface $conn, \Exception $e) |
62
|
|
|
{ |
63
|
|
|
echo "An error occurred: {$e->getMessage()}\n"; |
64
|
|
|
$conn->close(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
) |
68
|
|
|
), |
69
|
|
|
8080 |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$server->run(); |
73
|
|
|
|
74
|
|
|
return Command::SUCCESS; |
75
|
|
|
} |
76
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths