diff --git a/src/PubSub/Drivers/RedisClient.php b/src/PubSub/Drivers/RedisClient.php index ce9c8fb..2c8d916 100644 --- a/src/PubSub/Drivers/RedisClient.php +++ b/src/PubSub/Drivers/RedisClient.php @@ -117,7 +117,7 @@ class RedisClient implements ReplicationInterface unset($payload->appId); // Push the message out to connected websocket clients - $channel->broadcastToEveryoneExcept($payload, $socket); + $channel->broadcastToEveryoneExcept($payload, $socket, $appId, false); } /** diff --git a/src/WebSockets/Channels/Channel.php b/src/WebSockets/Channels/Channel.php index 8cf1469..5d69510 100644 --- a/src/WebSockets/Channels/Channel.php +++ b/src/WebSockets/Channels/Channel.php @@ -110,14 +110,19 @@ class Channel public function broadcastToOthers(ConnectionInterface $connection, $payload) { - // Also broadcast via the other websocket servers - $this->replication->publish($connection->app->id, $this->channelName, $payload); - - $this->broadcastToEveryoneExcept($payload, $connection->socketId); + $this->broadcastToEveryoneExcept($payload, $connection->socketId, $connection->app->id); } - public function broadcastToEveryoneExcept($payload, ?string $socketId = null) + public function broadcastToEveryoneExcept($payload, ?string $socketId, string $appId, bool $publish = true) { + // Also broadcast via the other websocket server instances. + // This is set false in the Redis client because we don't want to cause a loop + // in this case. If this came from TriggerEventController, then we still want + // to publish to get the message out to other server instances. + if ($publish) { + $this->replication->publish($appId, $this->channelName, $payload); + } + // Performance optimization, if we don't have a socket ID, // then we avoid running the if condition in the foreach loop below // by calling broadcast() instead.