Skip to content

Commit 192a729

Browse files
committed
Dont filter out duplicate connections
1 parent 0da752e commit 192a729

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Driver.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,20 @@ protected function generateSignaturePresence(string $channel, string $socketId,
112112
*/
113113
public function broadcast(array $channels, $event, array $payload = [])
114114
{
115-
$data = json_encode([
116-
'event' => $event,
117-
'data' => $payload,
118-
], JSON_THROW_ON_ERROR);
119-
120115
$skipConnectionId = Arr::pull($payload, 'socket');
121116

122-
$this->subscriptionRepository->getConnectionIdsForChannels(...$channels)
123-
->reject(fn($connectionId) => $connectionId === $skipConnectionId)
124-
->tap(fn($collection) => logger()->debug("Preparing to send to connections", $collection->toArray()))
125-
->each(fn(string $connectionId) => $this->sendMessage($connectionId, $data));
117+
foreach ($channels as $channel) {
118+
$data = json_encode([
119+
'event' => $event,
120+
'channel' => $channel,
121+
'data' => $payload,
122+
], JSON_THROW_ON_ERROR);
123+
124+
$this->subscriptionRepository->getConnectionIdsForChannel($channel)
125+
->reject(fn($connectionId) => $connectionId === $skipConnectionId)
126+
->tap(fn($connectionIds) => logger()->debug("Preparing to send to connections for channel '{$channel}'", $connectionIds->toArray()))
127+
->each(fn(string $connectionId) => $this->sendMessage($connectionId, $data));
128+
}
126129

127130
return;
128131

src/SubscriptionRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(array $config)
2121
$this->table = $config['table'];
2222
}
2323

24-
public function getConnectionIdsForChannels(string ...$channels): Collection
24+
public function getConnectionIdsForChannel(string ...$channels): Collection
2525
{
2626
$promises = collect($channels)->map(fn($channel) => $this->dynamoDb->queryAsync([
2727
'TableName' => $this->table,

0 commit comments

Comments
 (0)