diff --git a/src/Protocols/Pusher/Http/Controllers/EventsController.php b/src/Protocols/Pusher/Http/Controllers/EventsController.php index 381125ef..75b06f2c 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,8 +45,7 @@ public function __invoke(RequestInterface $request, Connection $connection, stri 'channels' => $channels, 'data' => $payload['data'], ], - isset($payload['socket_id']) ? (!empty($this->channels?->connections()[$payload['socket_id']]) ? - $this->channels?->connections()[$payload['socket_id']]->connection() : null) : 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 397d3e45..82373162 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php @@ -78,6 +78,27 @@ 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' => 'data']), + 'socket_id' => 'invalid-socket-id', + ])); + + $connection->assertReceived('{"event":"NewEvent","data":"{\"some\":\"data\"}","channel":"test-channel-two"}', 2); + expect($response->getStatusCode())->toBe(200); + expect($response->getBody()->getContents())->toBe('{}'); +}); + it('validates invalid data', function ($payload) { await($this->signedPostRequest('events', $payload)); })