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) { foreach ($request->json()->get('channels', []) as $channelId) {
$channel = $this->channelManager->find($request->appId, $channelId); $channel = $this->channelManager->find($request->appId, $channelId);
optional($channel)->broadcast([ optional($channel)->broadcastToEveryoneExcept([
'channel' => $channelId, 'channel' => $channelId,
'event' => $request->json()->get('name'), 'event' => $request->json()->get('name'),
'data' => $request->json()->get('data'), 'data' => $request->json()->get('data'),
]); ], $request->json()->get('socket_id'));
} }
return $request->json()->all(); 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) public function broadcastToOthers(ConnectionInterface $connection, $payload)
{ {
Collection::make($this->subscriptions)->reject(function ($existingConnection) use ($connection) { $this->broadcastToEveryoneExcept($payload, $connection->socketId);
return $existingConnection->socketId === $connection->socketId;
})->each->send(json_encode($payload));
} }
public function toArray(): array public function toArray(): array