Skip to content

Commit 6c3e5b7

Browse files
committed
Comments
1 parent 265a083 commit 6c3e5b7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/AsyncClient.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public function channel(string $channel): Observable
155155
return $this->channels[$channel];
156156
}
157157

158+
// Ensure we only get messages for the given channel
158159
$channelMessages = $this->messages->filter(function (Event $event) use ($channel) {
159160
return $event->getChannel() !== '' && $event->getChannel() === $channel;
160161
});
@@ -174,12 +175,16 @@ public function channel(string $channel): Observable
174175
$this->subscribeOnChannel($channel);
175176

176177
return new CallbackDisposable(function () use ($channel, $subscription) {
178+
// Send unsubscribe event
177179
$this->send(['event' => 'pusher:unsubscribe', 'data' => ['channel' => $channel]]);
180+
// Dispose our own subscription to messages
178181
$subscription->dispose();
182+
// Remove our channel from the channel list so we don't resubscribe in case we reconnect
179183
unset($this->channels[$channel]);
180184
});
181185
});
182186

187+
// Share stream amount subscribers to this channel
183188
$this->channels[$channel] = $events->share();
184189
return $this->channels[$channel];
185190
}
@@ -194,6 +199,7 @@ public function channel(string $channel): Observable
194199
*/
195200
public function send(array $message): bool
196201
{
202+
// Don't send messages when we aren't connected
197203
if ($this->sendSubject === null) {
198204
return false;
199205
}

0 commit comments

Comments
 (0)