Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Nov 29, 2023
1 parent a900fb1 commit 10f0c95
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/Channels/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Reverb\Channels;

use Exception;
use Illuminate\Support\Arr;
use Laravel\Reverb\Contracts\ChannelConnectionManager;
use Laravel\Reverb\Contracts\Connection;
Expand Down Expand Up @@ -82,28 +81,40 @@ public function subscribed(Connection $connection): bool
*/
public function broadcast(array $payload, Connection $except = null): void
{
if ($except === null && ! isset($payload['except'])) {
$this->broadcastToAll($payload);

return;
}

$message = json_encode(
Arr::except($payload, 'except')
);

$chunks = array_chunk($this->connections(), 100);
foreach ($this->connections() as $connection) {
if ($except && $except->id() === $connection->connection()->id()) {
continue;
}

foreach ($chunks as $connections) {
foreach ($connections as $connection) {
if ($except && $except->id() === $connection->connection()->id()) {
continue;
}
if (isset($payload['except']) && $payload['except'] === $connection->connection()->id()) {
continue;
}

if (isset($payload['except']) && $payload['except'] === $connection->connection()->id()) {
continue;
}
$connection->send($message);
}
}

try {
$connection->send($message);
} catch (Exception $e) {
//
}
}
/**
* Send a broadcast to all connections.
*/
public function broadcastToAll(array $payload): void
{
$message = json_encode(
Arr::except($payload, 'except')
);

foreach ($this->connections() as $connection) {
$connection->send($message);
}
}

Expand Down

0 comments on commit 10f0c95

Please sign in to comment.