Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 22fcddb

Browse files
committed
docblocks
1 parent 7458c3e commit 22fcddb

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/PubSub/Drivers/RedisClient.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,29 @@
1515
class RedisClient implements ReplicationInterface
1616
{
1717
/**
18+
* The running loop.
19+
*
1820
* @var LoopInterface
1921
*/
2022
protected $loop;
2123

2224
/**
25+
* The unique server identifier.
26+
*
2327
* @var string
2428
*/
2529
protected $serverId;
2630

2731
/**
32+
* The pub client.
33+
*
2834
* @var Client
2935
*/
3036
protected $publishClient;
3137

3238
/**
39+
* The sub client.
40+
*
3341
* @var Client
3442
*/
3543
protected $subscribeClient;
@@ -45,7 +53,9 @@ class RedisClient implements ReplicationInterface
4553
protected $subscribedChannels = [];
4654

4755
/**
48-
* RedisClient constructor.
56+
* Create a new Redis client.
57+
*
58+
* @return void
4959
*/
5060
public function __construct()
5161
{
@@ -68,6 +78,7 @@ public function boot(LoopInterface $loop): ReplicationInterface
6878
$this->publishClient = $factory->createLazyClient($connectionUri);
6979
$this->subscribeClient = $factory->createLazyClient($connectionUri);
7080

81+
// The subscribed client gets a message, it triggers the onMessage().
7182
$this->subscribeClient->on('message', function ($channel, $payload) {
7283
$this->onMessage($channel, $payload);
7384
});
@@ -86,7 +97,7 @@ protected function onMessage(string $redisChannel, string $payload)
8697
{
8798
$payload = json_decode($payload);
8899

89-
// Ignore messages sent by ourselves
100+
// Ignore messages sent by ourselves.
90101
if (isset($payload->serverId) && $this->serverId === $payload->serverId) {
91102
return;
92103
}
@@ -99,10 +110,9 @@ protected function onMessage(string $redisChannel, string $payload)
99110
// expect the channel name to not include the app ID.
100111
$payload->channel = Str::after($redisChannel, "$appId:");
101112

102-
/* @var ChannelManager $channelManager */
103113
$channelManager = app(ChannelManager::class);
104114

105-
// Load the Channel instance, if any
115+
// Load the Channel instance to sync.
106116
$channel = $channelManager->find($appId, $payload->channel);
107117

108118
// If no channel is found, none of our connections want to
@@ -113,12 +123,12 @@ protected function onMessage(string $redisChannel, string $payload)
113123

114124
$socket = $payload->socket ?? null;
115125

116-
// Remove fields intended for internal use from the payload
126+
// Remove fields intended for internal use from the payload.
117127
unset($payload->socket);
118128
unset($payload->serverId);
119129
unset($payload->appId);
120130

121-
// Push the message out to connected websocket clients
131+
// Push the message out to connected websocket clients.
122132
$channel->broadcastToEveryoneExcept($payload, $socket, $appId, false);
123133
}
124134

tests/TestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
2121
/** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */
2222
protected $channelManager;
2323

24+
/**
25+
* {@inheritdoc}
26+
*/
2427
public function setUp(): void
2528
{
2629
parent::setUp();
@@ -37,13 +40,19 @@ public function setUp(): void
3740
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
3841
}
3942

43+
/**
44+
* {@inheritdoc}
45+
*/
4046
protected function getPackageProviders($app)
4147
{
4248
return [
4349
\BeyondCode\LaravelWebSockets\WebSocketsServiceProvider::class,
4450
];
4551
}
4652

53+
/**
54+
* {@inheritdoc}
55+
*/
4756
protected function getEnvironmentSetUp($app)
4857
{
4958
$app['config']->set('websockets.apps', [

0 commit comments

Comments
 (0)