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

Commit 5997dd4

Browse files
committed
wip docblocks
1 parent 5838aca commit 5997dd4

File tree

5 files changed

+105
-80
lines changed

5 files changed

+105
-80
lines changed

src/PubSub/Drivers/LocalClient.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LocalClient implements ReplicationInterface
2020
/**
2121
* Boot the pub/sub provider (open connections, initial subscriptions, etc).
2222
*
23-
* @param LoopInterface $loop
23+
* @param LoopInterface $loop
2424
* @return self
2525
*/
2626
public function boot(LoopInterface $loop): ReplicationInterface
@@ -31,9 +31,9 @@ public function boot(LoopInterface $loop): ReplicationInterface
3131
/**
3232
* Publish a payload on a specific channel, for a specific app.
3333
*
34-
* @param string $appId
35-
* @param string $channel
36-
* @param stdClass $payload
34+
* @param string $appId
35+
* @param string $channel
36+
* @param stdClass $payload
3737
* @return bool
3838
*/
3939
public function publish(string $appId, string $channel, stdClass $payload): bool
@@ -44,8 +44,8 @@ public function publish(string $appId, string $channel, stdClass $payload): bool
4444
/**
4545
* Subscribe to receive messages for a channel.
4646
*
47-
* @param string $appId
48-
* @param string $channel
47+
* @param string $appId
48+
* @param string $channel
4949
* @return bool
5050
*/
5151
public function subscribe(string $appId, string $channel): bool
@@ -56,8 +56,8 @@ public function subscribe(string $appId, string $channel): bool
5656
/**
5757
* Unsubscribe from a channel.
5858
*
59-
* @param string $appId
60-
* @param string $channel
59+
* @param string $appId
60+
* @param string $channel
6161
* @return bool
6262
*/
6363
public function unsubscribe(string $appId, string $channel): bool
@@ -69,10 +69,11 @@ public function unsubscribe(string $appId, string $channel): bool
6969
* Add a member to a channel. To be called when they have
7070
* subscribed to the channel.
7171
*
72-
* @param string $appId
73-
* @param string $channel
74-
* @param string $socketId
75-
* @param string $data
72+
* @param string $appId
73+
* @param string $channel
74+
* @param string $socketId
75+
* @param string $data
76+
* @return void
7677
*/
7778
public function joinChannel(string $appId, string $channel, string $socketId, string $data)
7879
{
@@ -83,13 +84,15 @@ public function joinChannel(string $appId, string $channel, string $socketId, st
8384
* Remove a member from the channel. To be called when they have
8485
* unsubscribed from the channel.
8586
*
86-
* @param string $appId
87-
* @param string $channel
88-
* @param string $socketId
87+
* @param string $appId
88+
* @param string $channel
89+
* @param string $socketId
90+
* @return void
8991
*/
9092
public function leaveChannel(string $appId, string $channel, string $socketId)
9193
{
9294
unset($this->channelData["$appId:$channel"][$socketId]);
95+
9396
if (empty($this->channelData["$appId:$channel"])) {
9497
unset($this->channelData["$appId:$channel"]);
9598
}
@@ -98,15 +101,14 @@ public function leaveChannel(string $appId, string $channel, string $socketId)
98101
/**
99102
* Retrieve the full information about the members in a presence channel.
100103
*
101-
* @param string $appId
102-
* @param string $channel
104+
* @param string $appId
105+
* @param string $channel
103106
* @return PromiseInterface
104107
*/
105108
public function channelMembers(string $appId, string $channel): PromiseInterface
106109
{
107110
$members = $this->channelData["$appId:$channel"] ?? [];
108111

109-
// The data is expected as objects, so we need to JSON decode
110112
$members = array_map(function ($user) {
111113
return json_decode($user);
112114
}, $members);
@@ -117,8 +119,8 @@ public function channelMembers(string $appId, string $channel): PromiseInterface
117119
/**
118120
* Get the amount of users subscribed for each presence channel.
119121
*
120-
* @param string $appId
121-
* @param array $channelNames
122+
* @param string $appId
123+
* @param array $channelNames
122124
* @return PromiseInterface
123125
*/
124126
public function channelMemberCounts(string $appId, array $channelNames): PromiseInterface

src/PubSub/Drivers/RedisClient.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct()
5454
/**
5555
* Boot the RedisClient, initializing the connections.
5656
*
57-
* @param LoopInterface $loop
57+
* @param LoopInterface $loop
5858
* @return ReplicationInterface
5959
*/
6060
public function boot(LoopInterface $loop): ReplicationInterface
@@ -77,8 +77,9 @@ public function boot(LoopInterface $loop): ReplicationInterface
7777
/**
7878
* Handle a message received from Redis on a specific channel.
7979
*
80-
* @param string $redisChannel
81-
* @param string $payload
80+
* @param string $redisChannel
81+
* @param string $payload
82+
* @return void
8283
*/
8384
protected function onMessage(string $redisChannel, string $payload)
8485
{
@@ -123,8 +124,8 @@ protected function onMessage(string $redisChannel, string $payload)
123124
/**
124125
* Subscribe to a channel on behalf of websocket user.
125126
*
126-
* @param string $appId
127-
* @param string $channel
127+
* @param string $appId
128+
* @param string $channel
128129
* @return bool
129130
*/
130131
public function subscribe(string $appId, string $channel): bool
@@ -144,8 +145,8 @@ public function subscribe(string $appId, string $channel): bool
144145
/**
145146
* Unsubscribe from a channel on behalf of a websocket user.
146147
*
147-
* @param string $appId
148-
* @param string $channel
148+
* @param string $appId
149+
* @param string $channel
149150
* @return bool
150151
*/
151152
public function unsubscribe(string $appId, string $channel): bool
@@ -169,9 +170,9 @@ public function unsubscribe(string $appId, string $channel): bool
169170
/**
170171
* Publish a message to a channel on behalf of a websocket user.
171172
*
172-
* @param string $appId
173-
* @param string $channel
174-
* @param stdClass $payload
173+
* @param string $appId
174+
* @param string $channel
175+
* @param stdClass $payload
175176
* @return bool
176177
*/
177178
public function publish(string $appId, string $channel, stdClass $payload): bool
@@ -188,10 +189,11 @@ public function publish(string $appId, string $channel, stdClass $payload): bool
188189
* Add a member to a channel. To be called when they have
189190
* subscribed to the channel.
190191
*
191-
* @param string $appId
192-
* @param string $channel
193-
* @param string $socketId
194-
* @param string $data
192+
* @param string $appId
193+
* @param string $channel
194+
* @param string $socketId
195+
* @param string $data
196+
* @return void
195197
*/
196198
public function joinChannel(string $appId, string $channel, string $socketId, string $data)
197199
{
@@ -202,9 +204,10 @@ public function joinChannel(string $appId, string $channel, string $socketId, st
202204
* Remove a member from the channel. To be called when they have
203205
* unsubscribed from the channel.
204206
*
205-
* @param string $appId
206-
* @param string $channel
207-
* @param string $socketId
207+
* @param string $appId
208+
* @param string $channel
209+
* @param string $socketId
210+
* @return void
208211
*/
209212
public function leaveChannel(string $appId, string $channel, string $socketId)
210213
{
@@ -214,8 +217,8 @@ public function leaveChannel(string $appId, string $channel, string $socketId)
214217
/**
215218
* Retrieve the full information about the members in a presence channel.
216219
*
217-
* @param string $appId
218-
* @param string $channel
220+
* @param string $appId
221+
* @param string $channel
219222
* @return PromiseInterface
220223
*/
221224
public function channelMembers(string $appId, string $channel): PromiseInterface
@@ -232,8 +235,8 @@ public function channelMembers(string $appId, string $channel): PromiseInterface
232235
/**
233236
* Get the amount of users subscribed for each presence channel.
234237
*
235-
* @param string $appId
236-
* @param array $channelNames
238+
* @param string $appId
239+
* @param array $channelNames
237240
* @return PromiseInterface
238241
*/
239242
public function channelMemberCounts(string $appId, array $channelNames): PromiseInterface

src/PubSub/ReplicationInterface.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@ interface ReplicationInterface
1111
/**
1212
* Boot the pub/sub provider (open connections, initial subscriptions, etc).
1313
*
14-
* @param LoopInterface $loop
14+
* @param LoopInterface $loop
1515
* @return self
1616
*/
1717
public function boot(LoopInterface $loop): self;
1818

1919
/**
2020
* Publish a payload on a specific channel, for a specific app.
2121
*
22-
* @param string $appId
23-
* @param string $channel
24-
* @param stdClass $payload
22+
* @param string $appId
23+
* @param string $channel
24+
* @param stdClass $payload
2525
* @return bool
2626
*/
2727
public function publish(string $appId, string $channel, stdClass $payload): bool;
2828

2929
/**
3030
* Subscribe to receive messages for a channel.
3131
*
32-
* @param string $appId
33-
* @param string $channel
32+
* @param string $appId
33+
* @param string $channel
3434
* @return bool
3535
*/
3636
public function subscribe(string $appId, string $channel): bool;
3737

3838
/**
3939
* Unsubscribe from a channel.
4040
*
41-
* @param string $appId
42-
* @param string $channel
41+
* @param string $appId
42+
* @param string $channel
4343
* @return bool
4444
*/
4545
public function unsubscribe(string $appId, string $channel): bool;
@@ -48,37 +48,39 @@ public function unsubscribe(string $appId, string $channel): bool;
4848
* Add a member to a channel. To be called when they have
4949
* subscribed to the channel.
5050
*
51-
* @param string $appId
52-
* @param string $channel
53-
* @param string $socketId
54-
* @param string $data
51+
* @param string $appId
52+
* @param string $channel
53+
* @param string $socketId
54+
* @param string $data
55+
* @return void
5556
*/
5657
public function joinChannel(string $appId, string $channel, string $socketId, string $data);
5758

5859
/**
5960
* Remove a member from the channel. To be called when they have
6061
* unsubscribed from the channel.
6162
*
62-
* @param string $appId
63-
* @param string $channel
64-
* @param string $socketId
63+
* @param string $appId
64+
* @param string $channel
65+
* @param string $socketId
66+
* @return void
6567
*/
6668
public function leaveChannel(string $appId, string $channel, string $socketId);
6769

6870
/**
6971
* Retrieve the full information about the members in a presence channel.
7072
*
71-
* @param string $appId
72-
* @param string $channel
73+
* @param string $appId
74+
* @param string $channel
7375
* @return PromiseInterface
7476
*/
7577
public function channelMembers(string $appId, string $channel): PromiseInterface;
7678

7779
/**
7880
* Get the amount of users subscribed for each presence channel.
7981
*
80-
* @param string $appId
81-
* @param array $channelNames
82+
* @param string $appId
83+
* @param array $channelNames
8284
* @return PromiseInterface
8385
*/
8486
public function channelMemberCounts(string $appId, array $channelNames): PromiseInterface;

src/WebSockets/Channels/Channel.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,18 @@ public function subscribe(ConnectionInterface $connection, stdClass $payload)
6767
{
6868
$this->saveConnection($connection);
6969

70-
// Subscribe to broadcasted messages from the pub/sub backend
71-
$this->replicator->subscribe($connection->app->id, $this->channelName);
72-
7370
$connection->send(json_encode([
7471
'event' => 'pusher_internal:subscription_succeeded',
7572
'channel' => $this->channelName,
7673
]));
74+
75+
$this->replicator->subscribe($connection->app->id, $this->channelName);
7776
}
7877

7978
public function unsubscribe(ConnectionInterface $connection)
8079
{
8180
unset($this->subscribedConnections[$connection->socketId]);
8281

83-
// Unsubscribe from the pub/sub backend
8482
$this->replicator->unsubscribe($connection->app->id, $this->channelName);
8583

8684
if (! $this->hasConnections()) {

0 commit comments

Comments
 (0)