2018-11-21 22:47:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-11-27 15:11:12 +00:00
|
|
|
namespace BeyondCode\LaravelWebSockets\WebSockets\Messages;
|
2018-11-21 22:47:46 +00:00
|
|
|
|
2018-12-04 21:22:33 +00:00
|
|
|
use stdClass;
|
2019-02-27 14:27:21 +00:00
|
|
|
use Illuminate\Support\Str;
|
2018-12-04 21:22:33 +00:00
|
|
|
use Ratchet\ConnectionInterface;
|
2018-11-29 10:59:17 +00:00
|
|
|
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
|
2018-11-27 15:35:28 +00:00
|
|
|
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
|
2018-11-21 22:47:46 +00:00
|
|
|
|
2018-12-01 14:09:05 +00:00
|
|
|
class PusherClientMessage implements PusherMessage
|
2018-11-21 22:47:46 +00:00
|
|
|
{
|
|
|
|
|
/** \stdClass */
|
|
|
|
|
protected $payload;
|
|
|
|
|
|
|
|
|
|
/** @var \Ratchet\ConnectionInterface */
|
|
|
|
|
protected $connection;
|
|
|
|
|
|
2018-11-27 15:43:41 +00:00
|
|
|
/** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */
|
2018-11-21 22:47:46 +00:00
|
|
|
protected $channelManager;
|
|
|
|
|
|
|
|
|
|
public function __construct(stdClass $payload, ConnectionInterface $connection, ChannelManager $channelManager)
|
|
|
|
|
{
|
|
|
|
|
$this->payload = $payload;
|
|
|
|
|
|
|
|
|
|
$this->connection = $connection;
|
|
|
|
|
|
|
|
|
|
$this->channelManager = $channelManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function respond()
|
|
|
|
|
{
|
2019-02-27 14:27:21 +00:00
|
|
|
if (! Str::startsWith($this->payload->event, 'client-')) {
|
2018-11-26 23:13:22 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2018-11-25 21:24:31 +00:00
|
|
|
|
2018-12-01 14:59:46 +00:00
|
|
|
if (! $this->connection->app->clientMessagesEnabled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 10:59:17 +00:00
|
|
|
DashboardLogger::clientMessage($this->connection, $this->payload);
|
2018-11-21 22:47:46 +00:00
|
|
|
|
2018-12-01 13:12:15 +00:00
|
|
|
$channel = $this->channelManager->find($this->connection->app->id, $this->payload->channel);
|
2018-11-26 23:13:22 +00:00
|
|
|
|
2018-12-04 20:04:19 +00:00
|
|
|
optional($channel)->broadcastToOthers($this->connection, $this->payload);
|
2018-11-21 22:47:46 +00:00
|
|
|
}
|
2018-12-04 21:22:33 +00:00
|
|
|
}
|