Attempt at making TriggerEventController also publish to other servers

This commit is contained in:
Francis Lavoie 2019-07-29 17:39:34 -04:00
parent 091f56ea15
commit ef86f86668
No known key found for this signature in database
GPG Key ID: B9E0E04A76AF4692
2 changed files with 11 additions and 6 deletions

View File

@ -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);
}
/**

View File

@ -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.