This commit is contained in:
Marcel Pociot 2018-11-22 22:30:28 +01:00
parent b698b95147
commit f9d44040eb
2 changed files with 10 additions and 5 deletions

View File

@ -23,11 +23,11 @@ class TriggerEvent extends EchoController
foreach ($request->json()->get('channels', []) as $channelId) {
$channel = $this->channelManager->find($request->appId, $channelId);
optional($channel)->broadcast([
optional($channel)->broadcastToEveryoneExcept([
'channel' => $channelId,
'event' => $request->json()->get('name'),
'data' => $request->json()->get('data'),
]);
], $request->json()->get('socket_id'));
}
return $request->json()->all();

View File

@ -71,11 +71,16 @@ class Channel
}
}
public function broadcastToEveryoneExcept($payload, ?string $socketId = null)
{
Collection::make($this->subscriptions)->reject(function ($existingConnection) use ($socketId) {
return $existingConnection->socketId === $socketId;
})->each->send(json_encode($payload));
}
public function broadcastToOthers(ConnectionInterface $connection, $payload)
{
Collection::make($this->subscriptions)->reject(function ($existingConnection) use ($connection) {
return $existingConnection->socketId === $connection->socketId;
})->each->send(json_encode($payload));
$this->broadcastToEveryoneExcept($payload, $connection->socketId);
}
public function toArray(): array