From c514d7f6bda9cd4591c47419134aa950202bff6b Mon Sep 17 00:00:00 2001 From: law Date: Thu, 5 Dec 2024 16:04:51 +0100 Subject: [PATCH] Omit the socket_id key from the payload, unless a socket_id exists --- src/Protocols/Pusher/EventDispatcher.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Protocols/Pusher/EventDispatcher.php b/src/Protocols/Pusher/EventDispatcher.php index fe5830a..e47b80b 100644 --- a/src/Protocols/Pusher/EventDispatcher.php +++ b/src/Protocols/Pusher/EventDispatcher.php @@ -24,12 +24,15 @@ public static function dispatch(Application $app, array $payload, ?Connection $c return; } - app(PubSubProvider::class)->publish([ + $data = [ 'type' => 'message', 'application' => serialize($app), 'payload' => $payload, - 'socket_id' => $connection?->id(), - ]); + ]; + if ($connection?->id() !== null) { + $data['socket_id'] = $connection?->id(); + } + app(PubSubProvider::class)->publish($data); } /**