File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,7 @@ public function channel(string $channel): Observable
155
155
return $ this ->channels [$ channel ];
156
156
}
157
157
158
+ // Ensure we only get messages for the given channel
158
159
$ channelMessages = $ this ->messages ->filter (function (Event $ event ) use ($ channel ) {
159
160
return $ event ->getChannel () !== '' && $ event ->getChannel () === $ channel ;
160
161
});
@@ -174,12 +175,16 @@ public function channel(string $channel): Observable
174
175
$ this ->subscribeOnChannel ($ channel );
175
176
176
177
return new CallbackDisposable (function () use ($ channel , $ subscription ) {
178
+ // Send unsubscribe event
177
179
$ this ->send (['event ' => 'pusher:unsubscribe ' , 'data ' => ['channel ' => $ channel ]]);
180
+ // Dispose our own subscription to messages
178
181
$ subscription ->dispose ();
182
+ // Remove our channel from the channel list so we don't resubscribe in case we reconnect
179
183
unset($ this ->channels [$ channel ]);
180
184
});
181
185
});
182
186
187
+ // Share stream amount subscribers to this channel
183
188
$ this ->channels [$ channel ] = $ events ->share ();
184
189
return $ this ->channels [$ channel ];
185
190
}
@@ -194,6 +199,7 @@ public function channel(string $channel): Observable
194
199
*/
195
200
public function send (array $ message ): bool
196
201
{
202
+ // Don't send messages when we aren't connected
197
203
if ($ this ->sendSubject === null ) {
198
204
return false ;
199
205
}
You can’t perform that action at this time.
0 commit comments