diff --git a/src/Protocols/Pusher/Http/Controllers/EventsController.php b/src/Protocols/Pusher/Http/Controllers/EventsController.php index 315ddd02..285f42ca 100644 --- a/src/Protocols/Pusher/Http/Controllers/EventsController.php +++ b/src/Protocols/Pusher/Http/Controllers/EventsController.php @@ -34,6 +34,9 @@ public function __invoke(RequestInterface $request, Connection $connection, stri } $channels = Arr::wrap($payload['channels'] ?? $payload['channel'] ?? []); + if ($except = $payload['socket_id'] ?? null) { + $except = $this->channels->connections()[$except] ?? null; + } EventDispatcher::dispatch( $this->application, @@ -42,7 +45,7 @@ public function __invoke(RequestInterface $request, Connection $connection, stri 'channels' => $channels, 'data' => $payload['data'], ], - isset($payload['socket_id']) ? $this->channels->connections()[$payload['socket_id']]->connection() : null + $except ? $except->connection() : null ); if (isset($payload['info'])) { diff --git a/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php index 759a65a8..24dc30d1 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php @@ -78,6 +78,28 @@ expect($response->getBody()->getContents())->toBe('{}'); }); +it('does not fail when ignoring an invalid subscriber', function () { + $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' => ['more' => 'data']]), + 'socket_id' => 'invalid-socket-id', + ])); + + $connection->assertReceived('{"event":"NewEvent","data":"{\"some\":\"data\"}","channel":"test-channel-two"}', 1); + $connection->assertReceived('{"event":"NewEvent","data":"{\"some\":{\"more\":\"data\"}}","channel":"test-channel-two"}', 1); + expect($response->getStatusCode())->toBe(200); + expect($response->getBody()->getContents())->toBe('{}'); +}); + it('validates invalid data', function ($payload) { await($this->signedPostRequest('events', $payload)); })