diff --git a/src/Channels/Channel.php b/src/Channels/Channel.php index b71f7317..79dbac96 100644 --- a/src/Channels/Channel.php +++ b/src/Channels/Channel.php @@ -91,7 +91,7 @@ public function broadcast(Application $app, array $payload, Connection $except = /** * Get the data associated with the channel. */ - public function data(Application $app): array + public function data(): array { return []; } diff --git a/src/Channels/PresenceChannel.php b/src/Channels/PresenceChannel.php index dd7b6c79..43dc34f4 100644 --- a/src/Channels/PresenceChannel.php +++ b/src/Channels/PresenceChannel.php @@ -54,14 +54,24 @@ public function unsubscribe(Connection $connection): void /** * Get the data associated with the channel. */ - public function data(Application $app): array + public function data(): array { $connections = collect($this->connections->all()) ->map(fn ($connection) => $connection->data()); + if ($connections->contains(fn ($connection) => ! isset($connection['user_id']))) { + return [ + 'presence' => [ + 'count' => 0, + 'ids' => [], + 'hash' => [], + ], + ]; + } + return [ 'presence' => [ - 'count' => $connections->count(), + 'count' => $connections->count() ?? 0, 'ids' => $connections->map(fn ($connection) => $connection['user_id'])->all(), 'hash' => $connections->keyBy('user_id')->map->user_info->toArray(), ], diff --git a/src/Pusher/Event.php b/src/Pusher/Event.php index cb11312b..bfd813b9 100644 --- a/src/Pusher/Event.php +++ b/src/Pusher/Event.php @@ -51,7 +51,7 @@ public static function subscribe(Connection $connection, string $channel, string $channel->subscribe($connection, $auth, $data); - self::sendInternally($connection, 'subscription_succeeded', $channel->name(), $channel->data($connection->app())); + self::sendInternally($connection, 'subscription_succeeded', $channel->name(), $channel->data()); } /** diff --git a/tests/Feature/Ratchet/ChannelControllerTest.php b/tests/Feature/Reverb/ChannelControllerTest.php similarity index 100% rename from tests/Feature/Ratchet/ChannelControllerTest.php rename to tests/Feature/Reverb/ChannelControllerTest.php diff --git a/tests/Feature/Ratchet/ChannelUsersControllerTest.php b/tests/Feature/Reverb/ChannelUsersControllerTest.php similarity index 100% rename from tests/Feature/Ratchet/ChannelUsersControllerTest.php rename to tests/Feature/Reverb/ChannelUsersControllerTest.php diff --git a/tests/Feature/Ratchet/ChannelsControllerTest.php b/tests/Feature/Reverb/ChannelsControllerTest.php similarity index 100% rename from tests/Feature/Ratchet/ChannelsControllerTest.php rename to tests/Feature/Reverb/ChannelsControllerTest.php diff --git a/tests/Feature/Ratchet/EventsBatchControllerTest.php b/tests/Feature/Reverb/EventsBatchControllerTest.php similarity index 100% rename from tests/Feature/Ratchet/EventsBatchControllerTest.php rename to tests/Feature/Reverb/EventsBatchControllerTest.php diff --git a/tests/Feature/Ratchet/EventsControllerTest.php b/tests/Feature/Reverb/EventsControllerTest.php similarity index 100% rename from tests/Feature/Ratchet/EventsControllerTest.php rename to tests/Feature/Reverb/EventsControllerTest.php diff --git a/tests/Feature/Ratchet/ServerTest.php b/tests/Feature/Reverb/ServerTest.php similarity index 100% rename from tests/Feature/Ratchet/ServerTest.php rename to tests/Feature/Reverb/ServerTest.php diff --git a/tests/Feature/Ratchet/UsersTerminateControllerTest.php b/tests/Feature/Reverb/UsersTerminateControllerTest.php similarity index 100% rename from tests/Feature/Ratchet/UsersTerminateControllerTest.php rename to tests/Feature/Reverb/UsersTerminateControllerTest.php diff --git a/tests/Feature/ServerTest.php b/tests/Feature/ServerTest.php index d4d8b628..d1a4f0d4 100644 --- a/tests/Feature/ServerTest.php +++ b/tests/Feature/ServerTest.php @@ -118,7 +118,7 @@ 'event' => 'pusher:subscribe', 'data' => [ 'channel' => 'private-test-channel', - 'auth' => 'app-key:'.hash_hmac('sha256', '10000.00001:private-test-channel', 'pusher-secret'), + 'auth' => 'app-key:'.hash_hmac('sha256', $connection->id().':private-test-channel', 'pusher-secret'), ], ])); @@ -126,18 +126,16 @@ 'event' => 'pusher_internal:subscription_succeeded', 'channel' => 'private-test-channel', ]); -})->todo(); +}); it('can subscribe a user to a presence channel', function () { - $this->channelManager->shouldReceive('connections')->andReturn(Connections::make()); - $this->channelManager->shouldReceive('connectionKeys')->andReturn(collect()); $this->server->message( $connection = new Connection, json_encode([ 'event' => 'pusher:subscribe', 'data' => [ 'channel' => 'presence-test-channel', - 'auth' => 'app-key:'.hash_hmac('sha256', '10000.00001:presence-test-channel', 'pusher-secret'), + 'auth' => 'app-key:'.hash_hmac('sha256', $connection->id().':presence-test-channel', 'pusher-secret'), ], ])); @@ -152,7 +150,7 @@ ]), 'channel' => 'presence-test-channel', ]); -})->todo(); +}); it('unsubscribes a user from a channel on disconnection', function () { $channelManager = Mockery::spy(ChannelManager::class);