diff --git a/src/Protocols/Pusher/EventHandler.php b/src/Protocols/Pusher/EventHandler.php index 594b8ba5..5360fa04 100644 --- a/src/Protocols/Pusher/EventHandler.php +++ b/src/Protocols/Pusher/EventHandler.php @@ -161,6 +161,12 @@ public function formatPayload(string $event, array $data = [], ?string $channel */ public function formatInternalPayload(string $event, array $data = [], $channel = null): string|false { - return static::formatPayload($event, $data, $channel, 'pusher_internal:'); + return json_encode( + array_filter([ + 'event' => 'pusher_internal:'.$event, + 'data' => json_encode((object) $data), + 'channel' => $channel, + ]) + ); } } diff --git a/tests/Feature/Protocols/Pusher/Reverb/ServerTest.php b/tests/Feature/Protocols/Pusher/Reverb/ServerTest.php index f9f480f6..f449e635 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/ServerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/ServerTest.php @@ -21,13 +21,13 @@ $response = subscribe('test-channel'); expect(channels()->find('test-channel')->connections())->toHaveCount(1); - expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","channel":"test-channel"}'); + expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","data":"{}","channel":"test-channel"}'); }); it('can subscribe to a private channel', function () { $response = subscribe('private-test-channel'); - expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","channel":"private-test-channel"}'); + expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","data":"{}","channel":"private-test-channel"}'); }); it('can subscribe to a presence channel', function () { @@ -41,13 +41,13 @@ it('can subscribe to a cache channel', function () { $response = subscribe('cache-test-channel'); - expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","channel":"cache-test-channel"}'); + expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","data":"{}","channel":"cache-test-channel"}'); }); it('can subscribe to a private cache channel', function () { $response = subscribe('private-cache-test-channel'); - expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","channel":"private-cache-test-channel"}'); + expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","data":"{}","channel":"private-cache-test-channel"}'); }); it('can subscribe to a presence cache channel', function () { @@ -141,21 +141,21 @@ $connection->assertReceived('{"event":"App\\\\Events\\\\TestEvent","data":"{\"foo\":\"bar\"}","channel":"presence-cache-test-channel"}'); }); -it('can receive a cach missed message when joining a cache channel with an empty cache', function () { +it('can receive a cache missed message when joining a cache channel with an empty cache', function () { $connection = connect(); subscribe('cache-test-channel', connection: $connection); $connection->assertReceived('{"event":"pusher:cache_miss","channel":"cache-test-channel"}'); }); -it('can receive a cach missed message when joining a private cache channel with an empty cache', function () { +it('can receive a cache missed message when joining a private cache channel with an empty cache', function () { $connection = connect(); subscribe('private-cache-test-channel', connection: $connection); $connection->assertReceived('{"event":"pusher:cache_miss","channel":"private-cache-test-channel"}'); }); -it('can receive a cach missed message when joining a presence cache channel with an empty cache', function () { +it('can receive a cache missed message when joining a presence cache channel with an empty cache', function () { $connection = connect(); subscribe('presence-cache-test-channel', connection: $connection); @@ -455,7 +455,7 @@ ], ], $connection); - expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","channel":"my-channel"}'); + expect($response)->toBe('{"event":"pusher_internal:subscription_succeeded","data":"{}","channel":"my-channel"}'); }); it('buffers large requests correctly', function () { diff --git a/tests/Unit/Protocols/Pusher/EventTest.php b/tests/Unit/Protocols/Pusher/EventTest.php index fe629c6e..4d86d7d0 100644 --- a/tests/Unit/Protocols/Pusher/EventTest.php +++ b/tests/Unit/Protocols/Pusher/EventTest.php @@ -33,6 +33,7 @@ $this->connection->assertReceived([ 'event' => 'pusher_internal:subscription_succeeded', + 'data' => '{}', 'channel' => 'test-channel', ]); }); @@ -63,11 +64,10 @@ 'foo', ['bar' => 'baz'], 'test-channel', - 'reverb:' ); expect($payload)->toBe(json_encode([ - 'event' => 'reverb:foo', + 'event' => 'pusher:foo', 'data' => json_encode(['bar' => 'baz']), 'channel' => 'test-channel', ])); @@ -84,7 +84,6 @@ 'foo', ['bar' => 'baz'], 'test-channel', - 'reverb:' ); expect($payload)->toBe(json_encode([ @@ -97,5 +96,6 @@ expect($payload)->toBe(json_encode([ 'event' => 'pusher_internal:foo', + 'data' => '{}', ])); }); diff --git a/tests/Unit/Protocols/Pusher/ServerTest.php b/tests/Unit/Protocols/Pusher/ServerTest.php index 059de801..83f2eb3e 100644 --- a/tests/Unit/Protocols/Pusher/ServerTest.php +++ b/tests/Unit/Protocols/Pusher/ServerTest.php @@ -56,6 +56,7 @@ $connection->assertReceived([ 'event' => 'pusher_internal:subscription_succeeded', + 'data' => '{}', 'channel' => 'test-channel', ]); }); @@ -108,6 +109,7 @@ $connection->assertReceived([ 'event' => 'pusher_internal:subscription_succeeded', + 'data' => '{}', 'channel' => 'test-channel', ]); }); @@ -125,6 +127,7 @@ $connection->assertReceived([ 'event' => 'pusher_internal:subscription_succeeded', + 'data' => '{}', 'channel' => 'private-test-channel', ]); }); @@ -165,6 +168,7 @@ $connection->assertReceived([ 'event' => 'pusher_internal:subscription_succeeded', + 'data' => '{}', 'channel' => 'cache-test-channel', ]); $connection->assertReceived([ @@ -199,6 +203,7 @@ $connection->assertReceived([ 'event' => 'pusher_internal:subscription_succeeded', + 'data' => '{}', 'channel' => 'cache-test-channel', ]); $connection->assertReceived(['foo' => 'bar']);