docblocks
This commit is contained in:
parent
7458c3e09b
commit
22fcddb050
|
|
@ -15,21 +15,29 @@ use stdClass;
|
||||||
class RedisClient implements ReplicationInterface
|
class RedisClient implements ReplicationInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* The running loop.
|
||||||
|
*
|
||||||
* @var LoopInterface
|
* @var LoopInterface
|
||||||
*/
|
*/
|
||||||
protected $loop;
|
protected $loop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The unique server identifier.
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $serverId;
|
protected $serverId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The pub client.
|
||||||
|
*
|
||||||
* @var Client
|
* @var Client
|
||||||
*/
|
*/
|
||||||
protected $publishClient;
|
protected $publishClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The sub client.
|
||||||
|
*
|
||||||
* @var Client
|
* @var Client
|
||||||
*/
|
*/
|
||||||
protected $subscribeClient;
|
protected $subscribeClient;
|
||||||
|
|
@ -45,7 +53,9 @@ class RedisClient implements ReplicationInterface
|
||||||
protected $subscribedChannels = [];
|
protected $subscribedChannels = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RedisClient constructor.
|
* Create a new Redis client.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -68,6 +78,7 @@ class RedisClient implements ReplicationInterface
|
||||||
$this->publishClient = $factory->createLazyClient($connectionUri);
|
$this->publishClient = $factory->createLazyClient($connectionUri);
|
||||||
$this->subscribeClient = $factory->createLazyClient($connectionUri);
|
$this->subscribeClient = $factory->createLazyClient($connectionUri);
|
||||||
|
|
||||||
|
// The subscribed client gets a message, it triggers the onMessage().
|
||||||
$this->subscribeClient->on('message', function ($channel, $payload) {
|
$this->subscribeClient->on('message', function ($channel, $payload) {
|
||||||
$this->onMessage($channel, $payload);
|
$this->onMessage($channel, $payload);
|
||||||
});
|
});
|
||||||
|
|
@ -86,7 +97,7 @@ class RedisClient implements ReplicationInterface
|
||||||
{
|
{
|
||||||
$payload = json_decode($payload);
|
$payload = json_decode($payload);
|
||||||
|
|
||||||
// Ignore messages sent by ourselves
|
// Ignore messages sent by ourselves.
|
||||||
if (isset($payload->serverId) && $this->serverId === $payload->serverId) {
|
if (isset($payload->serverId) && $this->serverId === $payload->serverId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -99,10 +110,9 @@ class RedisClient implements ReplicationInterface
|
||||||
// expect the channel name to not include the app ID.
|
// expect the channel name to not include the app ID.
|
||||||
$payload->channel = Str::after($redisChannel, "$appId:");
|
$payload->channel = Str::after($redisChannel, "$appId:");
|
||||||
|
|
||||||
/* @var ChannelManager $channelManager */
|
|
||||||
$channelManager = app(ChannelManager::class);
|
$channelManager = app(ChannelManager::class);
|
||||||
|
|
||||||
// Load the Channel instance, if any
|
// Load the Channel instance to sync.
|
||||||
$channel = $channelManager->find($appId, $payload->channel);
|
$channel = $channelManager->find($appId, $payload->channel);
|
||||||
|
|
||||||
// If no channel is found, none of our connections want to
|
// If no channel is found, none of our connections want to
|
||||||
|
|
@ -113,12 +123,12 @@ class RedisClient implements ReplicationInterface
|
||||||
|
|
||||||
$socket = $payload->socket ?? null;
|
$socket = $payload->socket ?? null;
|
||||||
|
|
||||||
// Remove fields intended for internal use from the payload
|
// Remove fields intended for internal use from the payload.
|
||||||
unset($payload->socket);
|
unset($payload->socket);
|
||||||
unset($payload->serverId);
|
unset($payload->serverId);
|
||||||
unset($payload->appId);
|
unset($payload->appId);
|
||||||
|
|
||||||
// Push the message out to connected websocket clients
|
// Push the message out to connected websocket clients.
|
||||||
$channel->broadcastToEveryoneExcept($payload, $socket, $appId, false);
|
$channel->broadcastToEveryoneExcept($payload, $socket, $appId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
/** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */
|
/** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */
|
||||||
protected $channelManager;
|
protected $channelManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
@ -37,6 +40,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
|
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function getPackageProviders($app)
|
protected function getPackageProviders($app)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|
@ -44,6 +50,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function getEnvironmentSetUp($app)
|
protected function getEnvironmentSetUp($app)
|
||||||
{
|
{
|
||||||
$app['config']->set('websockets.apps', [
|
$app['config']->set('websockets.apps', [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue