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

Commit 417c832

Browse files
committed
updated pubsub messages
1 parent c622f77 commit 417c832

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/PubSub/Drivers/LocalClient.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function unsubscribe(string $appId, string $channel): bool
7878
*/
7979
public function joinChannel(string $appId, string $channel, string $socketId, string $data)
8080
{
81-
$this->channelData["$appId:$channel"][$socketId] = $data;
81+
$this->channelData["{$appId}:{$channel}"][$socketId] = $data;
8282
}
8383

8484
/**
@@ -92,10 +92,10 @@ public function joinChannel(string $appId, string $channel, string $socketId, st
9292
*/
9393
public function leaveChannel(string $appId, string $channel, string $socketId)
9494
{
95-
unset($this->channelData["$appId:$channel"][$socketId]);
95+
unset($this->channelData["{$appId}:{$channel}"][$socketId]);
9696

97-
if (empty($this->channelData["$appId:$channel"])) {
98-
unset($this->channelData["$appId:$channel"]);
97+
if (empty($this->channelData["{$appId}:{$channel}"])) {
98+
unset($this->channelData["{$appId}:{$channel}"]);
9999
}
100100
}
101101

@@ -108,7 +108,7 @@ public function leaveChannel(string $appId, string $channel, string $socketId)
108108
*/
109109
public function channelMembers(string $appId, string $channel): PromiseInterface
110110
{
111-
$members = $this->channelData["$appId:$channel"] ?? [];
111+
$members = $this->channelData["{$appId}:{$channel}"] ?? [];
112112

113113
$members = array_map(function ($user) {
114114
return json_decode($user);
@@ -130,8 +130,8 @@ public function channelMemberCounts(string $appId, array $channelNames): Promise
130130

131131
// Count the number of users per channel
132132
foreach ($channelNames as $channel) {
133-
$results[$channel] = isset($this->channelData["$appId:$channel"])
134-
? count($this->channelData["$appId:$channel"])
133+
$results[$channel] = isset($this->channelData["{$appId}:{$channel}"])
134+
? count($this->channelData["{$appId}:{$channel}"])
135135
: 0;
136136
}
137137

src/PubSub/Drivers/RedisClient.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ public function publish(string $appId, string $channel, stdClass $payload): bool
104104

105105
$payload = json_encode($payload);
106106

107-
$this->publishClient->__call('publish', ["$appId:$channel", $payload]);
107+
$this->publishClient->__call('publish', ["{$appId}:{$channel}", $payload]);
108108

109109
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_MESSAGE_PUBLISHED, [
110110
'channel' => $channel,
111111
'serverId' => $this->getServerId(),
112112
'payload' => $payload,
113+
'pubsub' => "{$appId}:{$channel}",
113114
]);
114115

115116
return true;
@@ -124,18 +125,19 @@ public function publish(string $appId, string $channel, stdClass $payload): bool
124125
*/
125126
public function subscribe(string $appId, string $channel): bool
126127
{
127-
if (! isset($this->subscribedChannels["$appId:$channel"])) {
128+
if (! isset($this->subscribedChannels["{$appId}:{$channel}"])) {
128129
// We're not subscribed to the channel yet, subscribe and set the count to 1
129-
$this->subscribeClient->__call('subscribe', ["$appId:$channel"]);
130-
$this->subscribedChannels["$appId:$channel"] = 1;
130+
$this->subscribeClient->__call('subscribe', ["{$appId}:{$channel}"]);
131+
$this->subscribedChannels["{$appId}:{$channel}"] = 1;
131132
} else {
132133
// Increment the subscribe count if we've already subscribed
133-
$this->subscribedChannels["$appId:$channel"]++;
134+
$this->subscribedChannels["{$appId}:{$channel}"]++;
134135
}
135136

136137
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_SUBSCRIBED, [
137138
'channel' => $channel,
138139
'serverId' => $this->getServerId(),
140+
'pubsub' => "{$appId}:{$channel}",
139141
]);
140142

141143
return true;
@@ -150,23 +152,24 @@ public function subscribe(string $appId, string $channel): bool
150152
*/
151153
public function unsubscribe(string $appId, string $channel): bool
152154
{
153-
if (! isset($this->subscribedChannels["$appId:$channel"])) {
155+
if (! isset($this->subscribedChannels["{$appId}:{$channel}"])) {
154156
return false;
155157
}
156158

157159
// Decrement the subscription count for this channel
158-
$this->subscribedChannels["$appId:$channel"]--;
160+
$this->subscribedChannels["{$appId}:{$channel}"]--;
159161

160162
// If we no longer have subscriptions to that channel, unsubscribe
161-
if ($this->subscribedChannels["$appId:$channel"] < 1) {
162-
$this->subscribeClient->__call('unsubscribe', ["$appId:$channel"]);
163+
if ($this->subscribedChannels["{$appId}:{$channel}"] < 1) {
164+
$this->subscribeClient->__call('unsubscribe', ["{$appId}:{$channel}"]);
163165

164-
unset($this->subscribedChannels["$appId:$channel"]);
166+
unset($this->subscribedChannels["{$appId}:{$channel}"]);
165167
}
166168

167169
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_UNSUBSCRIBED, [
168170
'channel' => $channel,
169171
'serverId' => $this->getServerId(),
172+
'pubsub' => "{$appId}:{$channel}",
170173
]);
171174

172175
return true;
@@ -184,13 +187,14 @@ public function unsubscribe(string $appId, string $channel): bool
184187
*/
185188
public function joinChannel(string $appId, string $channel, string $socketId, string $data)
186189
{
187-
$this->publishClient->__call('hset', ["$appId:$channel", $socketId, $data]);
190+
$this->publishClient->__call('hset', ["{$appId}:{$channel}", $socketId, $data]);
188191

189192
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_JOINED_CHANNEL, [
190193
'channel' => $channel,
191194
'serverId' => $this->getServerId(),
192195
'socketId' => $socketId,
193196
'data' => $data,
197+
'pubsub' => "{$appId}:{$channel}",
194198
]);
195199
}
196200

@@ -205,12 +209,13 @@ public function joinChannel(string $appId, string $channel, string $socketId, st
205209
*/
206210
public function leaveChannel(string $appId, string $channel, string $socketId)
207211
{
208-
$this->publishClient->__call('hdel', ["$appId:$channel", $socketId]);
212+
$this->publishClient->__call('hdel', ["{$appId}:{$channel}", $socketId]);
209213

210214
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_LEFT_CHANNEL, [
211215
'channel' => $channel,
212216
'serverId' => $this->getServerId(),
213217
'socketId' => $socketId,
218+
'pubsub' => "{$appId}:{$channel}",
214219
]);
215220
}
216221

@@ -223,7 +228,7 @@ public function leaveChannel(string $appId, string $channel, string $socketId)
223228
*/
224229
public function channelMembers(string $appId, string $channel): PromiseInterface
225230
{
226-
return $this->publishClient->__call('hgetall', ["$appId:$channel"])
231+
return $this->publishClient->__call('hgetall', ["{$appId}:{$channel}"])
227232
->then(function ($members) {
228233
// The data is expected as objects, so we need to JSON decode
229234
return array_map(function ($user) {
@@ -244,7 +249,7 @@ public function channelMemberCounts(string $appId, array $channelNames): Promise
244249
$this->publishClient->__call('multi', []);
245250

246251
foreach ($channelNames as $channel) {
247-
$this->publishClient->__call('hlen', ["$appId:$channel"]);
252+
$this->publishClient->__call('hlen', ["{$appId}:{$channel}"]);
248253
}
249254

250255
return $this->publishClient->__call('exec', [])

0 commit comments

Comments
 (0)