|
11 | 11 | use Amp\Websocket\Server\WebsocketClientHandler;
|
12 | 12 | use Amp\Websocket\WebsocketClient;
|
13 | 13 | use Closure;
|
| 14 | +use Flat3\RevPi\Constants; |
14 | 15 | use Flat3\RevPi\Exceptions\NotImplementedException;
|
15 | 16 | use Flat3\RevPi\Exceptions\RemoteDeviceException;
|
16 | 17 | use Flat3\RevPi\Interfaces\Hardware\Device;
|
@@ -59,13 +60,6 @@ public function withSocket(WebsocketClient $socket): self
|
59 | 60 | return $this;
|
60 | 61 | }
|
61 | 62 |
|
62 |
| - public function withDevice(Device $device): self |
63 |
| - { |
64 |
| - $this->device = $device; |
65 |
| - |
66 |
| - return $this; |
67 |
| - } |
68 |
| - |
69 | 63 | /**
|
70 | 64 | * @param JsonRpcMethodT $method
|
71 | 65 | * @param JsonRpcRequestParamsT $params
|
@@ -149,7 +143,7 @@ public function on(Closure $callback): void
|
149 | 143 | * @param array<string, int|string|null> $params
|
150 | 144 | * @return JsonRpcResponseResultT
|
151 | 145 | */
|
152 |
| - public function handle(string $method, array $params): mixed |
| 146 | + protected function handle(string $method, array $params): mixed |
153 | 147 | {
|
154 | 148 | switch ($method) {
|
155 | 149 | case 'open':
|
@@ -256,12 +250,12 @@ public function handle(string $method, array $params): mixed
|
256 | 250 | $stream = $this->device->fdopen();
|
257 | 251 |
|
258 | 252 | EventLoop::onReadable($stream, function ($callbackId, $stream) {
|
259 |
| - $newData = @fread($stream, 8192); |
| 253 | + $data = @fread($stream, Constants::BlockSize); |
260 | 254 |
|
261 |
| - if (is_string($newData) && $newData !== '') { |
| 255 | + if (is_string($data) && $data !== '') { |
262 | 256 | $request = new Event;
|
263 | 257 | $request->type = 'readable';
|
264 |
| - $request->payload = $newData; |
| 258 | + $request->payload = $data; |
265 | 259 |
|
266 | 260 | $this->socket->sendBinary(serialize($request));
|
267 | 261 | } elseif (! is_resource($stream) || @feof($stream)) {
|
|
0 commit comments