Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit ef86f86

Browse files
committed
Attempt at making TriggerEventController also publish to other servers
1 parent 091f56e commit ef86f86

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/PubSub/Drivers/RedisClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function onMessage(string $redisChannel, string $payload)
117117
unset($payload->appId);
118118

119119
// Push the message out to connected websocket clients
120-
$channel->broadcastToEveryoneExcept($payload, $socket);
120+
$channel->broadcastToEveryoneExcept($payload, $socket, $appId, false);
121121
}
122122

123123
/**

src/WebSockets/Channels/Channel.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,19 @@ public function broadcast($payload)
110110

111111
public function broadcastToOthers(ConnectionInterface $connection, $payload)
112112
{
113-
// Also broadcast via the other websocket servers
114-
$this->replication->publish($connection->app->id, $this->channelName, $payload);
115-
116-
$this->broadcastToEveryoneExcept($payload, $connection->socketId);
113+
$this->broadcastToEveryoneExcept($payload, $connection->socketId, $connection->app->id);
117114
}
118115

119-
public function broadcastToEveryoneExcept($payload, ?string $socketId = null)
116+
public function broadcastToEveryoneExcept($payload, ?string $socketId, string $appId, bool $publish = true)
120117
{
118+
// Also broadcast via the other websocket server instances.
119+
// This is set false in the Redis client because we don't want to cause a loop
120+
// in this case. If this came from TriggerEventController, then we still want
121+
// to publish to get the message out to other server instances.
122+
if ($publish) {
123+
$this->replication->publish($appId, $this->channelName, $payload);
124+
}
125+
121126
// Performance optimization, if we don't have a socket ID,
122127
// then we avoid running the if condition in the foreach loop below
123128
// by calling broadcast() instead.

0 commit comments

Comments
 (0)