1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI\Core\Objects\WebSockets; |
4
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Auth\Credentials; |
6
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\WebSockets\Entity\WebSocketConnectionResponse; |
7
|
|
|
use Workerman\Worker; |
|
|
|
|
8
|
|
|
use Workerman\Connection\AsyncTcpConnection; |
|
|
|
|
9
|
|
|
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder; |
10
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseDataInterface; |
11
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IChannelHandlerInterface; |
12
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IWebSocketArgumentInterface; |
13
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IWebSocketsChannelInterface; |
14
|
|
|
|
15
|
|
|
abstract class WebSocketsPublicChannel implements IWebSocketsChannelInterface |
16
|
|
|
{ |
17
|
|
|
public const CHANNEL_ACCESS = 'public'; |
18
|
|
|
protected string $hostStream; |
19
|
|
|
protected string $wsRoute; |
20
|
|
|
protected array $topic; |
21
|
|
|
protected string $operation; |
22
|
|
|
protected Worker $worker; |
23
|
|
|
protected IChannelHandlerInterface $callback; |
24
|
|
|
protected IResponseDataInterface $response; |
25
|
|
|
|
26
|
|
|
public function __construct( |
27
|
|
|
IWebSocketArgumentInterface $argument, |
28
|
|
|
Credentials $credentials, |
29
|
|
|
IChannelHandlerInterface $callback |
30
|
|
|
) { |
31
|
|
|
$this->worker = new Worker(); |
32
|
|
|
$this->topic = $argument->getTopic(); |
33
|
|
|
$this->operation = $this->getOperation(); |
|
|
|
|
34
|
|
|
$this->hostStream = $credentials->getHost(); |
35
|
|
|
$this->callback = $callback; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function execute(): void |
42
|
|
|
{ |
43
|
|
|
$this->worker->onWorkerStart = function () { |
44
|
|
|
|
45
|
|
|
$connection = new AsyncTcpConnection($this->hostStream . static::CHANNEL_TYPE . "/" . static::CHANNEL_ACCESS . "/v3"); |
|
|
|
|
46
|
|
|
|
47
|
|
|
$connection->transport = 'ssl'; |
48
|
|
|
$connection->onConnect = function ($connection) { |
49
|
|
|
$connection->send(json_encode(["op" => $this->operation, "args" => $this->topic])); |
50
|
|
|
}; |
51
|
|
|
|
52
|
|
|
$callback = $this->callback; |
53
|
|
|
|
54
|
|
|
$connection->onMessage = function ($connection, $message) use ($callback) { |
55
|
|
|
|
56
|
|
|
$message = json_decode($message, true); |
57
|
|
|
|
58
|
|
|
$responseDto = (empty($message['op'])) ? $this->getResponseClassname() : WebSocketConnectionResponse::class; |
59
|
|
|
|
60
|
|
|
$dtoMessage = ResponseDtoBuilder::make($responseDto, $message); |
61
|
|
|
$callback->handle($dtoMessage, $connection); |
|
|
|
|
62
|
|
|
}; |
63
|
|
|
|
64
|
|
|
$connection->connect(); |
65
|
|
|
}; |
66
|
|
|
|
67
|
|
|
Worker::runAll(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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