diff --git a/src/Protocols/Pusher/PusherPubSubIncomingMessageHandler.php b/src/Protocols/Pusher/PusherPubSubIncomingMessageHandler.php index aba121e0..32c16d6e 100644 --- a/src/Protocols/Pusher/PusherPubSubIncomingMessageHandler.php +++ b/src/Protocols/Pusher/PusherPubSubIncomingMessageHandler.php @@ -15,10 +15,7 @@ public function handle(string $payload): void $event = json_decode($payload, associative: true, flags: JSON_THROW_ON_ERROR); $application = unserialize($event['application']); - - $except = isset($event['socket_id']) ? - app(ChannelManager::class)->for($application)->connections()[$event['socket_id']] ?? null - : null; + $except = app(ChannelManager::class)->for($application)->connections()[$event['socket_id']] ?? null; match ($event['type'] ?? null) { 'message' => EventDispatcher::dispatchSynchronously( diff --git a/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php index a747e286..91b0fde9 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php @@ -78,6 +78,29 @@ expect($response->getBody()->getContents())->toBe('{}'); }); +it('can ignore a subscriber when publishing events over redis', function () { + $this->usingRedis(); + + $connection = connect(); + subscribe('test-channel-two', connection: $connection); + $response = await($this->signedPostRequest('events', [ + 'name' => 'NewEvent', + 'channels' => ['test-channel-one', 'test-channel-two'], + 'data' => json_encode(['some' => 'data']), + ])); + + $response = await($this->signedPostRequest('events', [ + 'name' => 'NewEvent', + 'channels' => ['test-channel-one', 'test-channel-two'], + 'data' => json_encode(['some' => 'data']), + 'socket_id' => $connection->socketId(), + ])); + + $connection->assertReceived('{"event":"NewEvent","data":"{\"some\":\"data\"}","channel":"test-channel-two"}', 1); + expect($response->getStatusCode())->toBe(200); + expect($response->getBody()->getContents())->toBe('{}'); +}); + it('does not fail when ignoring an invalid subscriber', function () { $connection = connect(); subscribe('test-channel-two', connection: $connection); diff --git a/tests/Unit/EventTest.php b/tests/Unit/EventTest.php index 7faa109c..d078c721 100644 --- a/tests/Unit/EventTest.php +++ b/tests/Unit/EventTest.php @@ -11,7 +11,7 @@ app(ServerProviderManager::class)->withPublishing(); $pubSub = Mockery::mock(PubSubProvider::class); $pubSub->shouldReceive('publish')->once() - ->with(['type' => 'message', 'application' => serialize($app), 'payload' => ['channel' => 'test-channel']]); + ->with(['type' => 'message', 'application' => serialize($app), 'payload' => ['channel' => 'test-channel'], 'socket_id' => null]); $this->app->instance(PubSubProvider::class, $pubSub);