laravel-websockets/src/LaravelEcho/WebSocket/Message.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2018-11-21 22:47:46 +00:00
<?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager;
2018-11-25 21:24:31 +00:00
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Dashboard;
2018-11-21 22:47:46 +00:00
use Ratchet\ConnectionInterface;
use stdClass;
class Message implements RespondableMessage
{
/** \stdClass */
protected $payload;
/** @var \Ratchet\ConnectionInterface */
protected $connection;
/** @var \BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager */
protected $channelManager;
public function __construct(stdClass $payload, ConnectionInterface $connection, ChannelManager $channelManager)
{
$this->payload = $payload;
$this->connection = $connection;
$this->channelManager = $channelManager;
}
public function respond()
{
2018-11-22 16:42:25 +00:00
if (starts_with($this->payload->event, 'client-')) {
2018-11-25 21:24:31 +00:00
Dashboard::clientMessage($this->connection, $this->payload);
2018-11-24 21:07:53 +00:00
$channel = $this->channelManager->find($this->connection->client->appId, $this->payload->channel);
2018-11-21 22:47:46 +00:00
2018-11-22 16:42:25 +00:00
optional($channel)->broadcast($this->payload);
}
2018-11-21 22:47:46 +00:00
}
}