commit
This commit is contained in:
parent
e8e79dfef3
commit
cc9fb7d7eb
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Dashboard;
|
|
||||||
|
|
||||||
class EventHandler
|
|
||||||
{
|
|
||||||
//TODO: listen for events, pass them to Dashboard:: methods
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeyondCode\LaravelWebSockets\Dashboard;
|
||||||
|
|
||||||
|
use BeyondCode\LaravelWebSockets\Events\ChannelVacated;
|
||||||
|
use BeyondCode\LaravelWebSockets\Events\ClientMessageSent;
|
||||||
|
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Dashboard;
|
||||||
|
use Illuminate\Events\Dispatcher;
|
||||||
|
|
||||||
|
class EventSubscriber
|
||||||
|
{
|
||||||
|
public function onChannelVacated(ChannelVacated $event)
|
||||||
|
{
|
||||||
|
Dashboard::vacated($event->connection, $event->channelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onClientMessageSent(ClientMessageSent $event)
|
||||||
|
{
|
||||||
|
Dashboard::clientMessage($event->connection, $event->payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function subscribe(Dispatcher $events)
|
||||||
|
{
|
||||||
|
$events->listen(ChannelVacated::class, static::class . '@onChannelVacated');
|
||||||
|
$events->listen(ClientMessageSent::class, static::class . '@onClientMessageSent');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeyondCode\LaravelWebSockets\Events;
|
||||||
|
|
||||||
|
use Ratchet\ConnectionInterface;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
|
class ClientMessageSent
|
||||||
|
{
|
||||||
|
/** @var \Ratchet\ConnectionInterface */
|
||||||
|
public $connection;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
public $payload;
|
||||||
|
|
||||||
|
public function __construct(ConnectionInterface $connection, stdClass $payload)
|
||||||
|
{
|
||||||
|
$this->connection = $connection;
|
||||||
|
|
||||||
|
$this->payload = $payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -61,7 +61,6 @@ class Channel
|
||||||
|
|
||||||
if (! $this->hasConnections()) {
|
if (! $this->hasConnections()) {
|
||||||
event(new ChannelVacated($connection, $this->channelId));
|
event(new ChannelVacated($connection, $this->channelId));
|
||||||
Dashboard::vacated($connection, $this->channelId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket;
|
namespace BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket;
|
||||||
|
|
||||||
|
use BeyondCode\LaravelWebSockets\Events\ClientMessageSent;
|
||||||
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager;
|
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager;
|
||||||
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Dashboard;
|
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Dashboard;
|
||||||
use Ratchet\ConnectionInterface;
|
use Ratchet\ConnectionInterface;
|
||||||
|
|
@ -30,7 +31,7 @@ class Message implements RespondableMessage
|
||||||
public function respond()
|
public function respond()
|
||||||
{
|
{
|
||||||
if (starts_with($this->payload->event, 'client-')) {
|
if (starts_with($this->payload->event, 'client-')) {
|
||||||
Dashboard::clientMessage($this->connection, $this->payload);
|
event(new ClientMessageSent($this->connection, $this->payload));
|
||||||
|
|
||||||
$channel = $this->channelManager->find($this->connection->client->appId, $this->payload->channel);
|
$channel = $this->channelManager->find($this->connection->client->appId, $this->payload->channel);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets;
|
namespace BeyondCode\LaravelWebSockets;
|
||||||
|
|
||||||
|
use BeyondCode\LaravelWebSockets\Dashboard\EventSubscriber;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use BeyondCode\LaravelWebSockets\ClientProviders\ClientProvider;
|
use BeyondCode\LaravelWebSockets\ClientProviders\ClientProvider;
|
||||||
|
|
@ -27,6 +29,8 @@ class WebSocketsServiceProvider extends ServiceProvider
|
||||||
$this->commands([
|
$this->commands([
|
||||||
Console\StartWebSocketServer::class,
|
Console\StartWebSocketServer::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Event::subscribe(EventSubscriber::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerRoutes()
|
protected function registerRoutes()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue