From 790725890804ed232e1dc9a92163994f4ead70d0 Mon Sep 17 00:00:00 2001 From: Blax Software Date: Mon, 20 Jan 2025 16:46:13 +0100 Subject: [PATCH] A progress response to controller --- src/Websocket/Controller.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Websocket/Controller.php b/src/Websocket/Controller.php index ceb54b8..40b8b6e 100644 --- a/src/Websocket/Controller.php +++ b/src/Websocket/Controller.php @@ -166,6 +166,35 @@ class Controller } } + final public function progress( + mixed $payload = null, + ?string $event = null, + ?string $channel = null + ) : bool { + $p = [ + 'event' => ($event ?? $this->event) . ':progress', + 'data' => $payload, + 'channel' => $channel ?? $this->channel->getName(), + ]; + + // if payload only contains key "data" + if ( + count($p) === 1 + && isset($payload['data']) + ) { + $p['data'] = $payload['data']; + } + + if (get_class($this->connection) === MockConnection::class) { + $connection = clone $this->connection; + $connection->send(json_encode($p)); + } else { + $this->connection->send(json_encode($p)); + } + + return true; + } + final public function success( mixed $payload = null, ?string $event = null,