From ae2e9feb0eed28aa3de397e3db0ec3a2f039f921 Mon Sep 17 00:00:00 2001 From: law Date: Tue, 26 Nov 2024 14:02:08 +0100 Subject: [PATCH] Fix for issue #246 Pass SocketID through redis, and filter it on the receiving end. This ensures that ->toOthers() works with scaling = true --- src/Protocols/Pusher/EventDispatcher.php | 2 +- .../Pusher/PusherPubSubIncomingMessageHandler.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Protocols/Pusher/EventDispatcher.php b/src/Protocols/Pusher/EventDispatcher.php index b94b5f39..a8718c8f 100644 --- a/src/Protocols/Pusher/EventDispatcher.php +++ b/src/Protocols/Pusher/EventDispatcher.php @@ -28,6 +28,7 @@ public static function dispatch(Application $app, array $payload, ?Connection $c 'type' => 'message', 'application' => serialize($app), 'payload' => $payload, + 'socket_id' => $connection?->id(), ]); } @@ -46,7 +47,6 @@ public static function dispatchSynchronously(Application $app, array $payload, ? } $payload['channel'] = $channel->name(); - $channel->broadcast($payload, $connection); } } diff --git a/src/Protocols/Pusher/PusherPubSubIncomingMessageHandler.php b/src/Protocols/Pusher/PusherPubSubIncomingMessageHandler.php index 55db23e3..aba121e0 100644 --- a/src/Protocols/Pusher/PusherPubSubIncomingMessageHandler.php +++ b/src/Protocols/Pusher/PusherPubSubIncomingMessageHandler.php @@ -16,10 +16,15 @@ public function handle(string $payload): void $application = unserialize($event['application']); + $except = isset($event['socket_id']) ? + app(ChannelManager::class)->for($application)->connections()[$event['socket_id']] ?? null + : null; + match ($event['type'] ?? null) { 'message' => EventDispatcher::dispatchSynchronously( $application, - $event['payload'] + $event['payload'], + $except?->connection() ), 'metrics' => app(MetricsHandler::class)->publish( $application,