From 35336c7ee4c3e5c281ae44d859bb13ed2b2fcbf4 Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Sun, 19 Nov 2023 21:00:42 +0000 Subject: [PATCH] implements users routes --- .../Http/Controllers/ChannelController.php | 6 +----- .../Http/Controllers/ChannelUsersController.php | 11 ++++++++++- src/Servers/Reverb/Factory.php | 2 +- .../Ratchet/ChannelUsersControllerTest.php | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 tests/Feature/Ratchet/ChannelUsersControllerTest.php diff --git a/src/Pusher/Http/Controllers/ChannelController.php b/src/Pusher/Http/Controllers/ChannelController.php index a6423ebe..b9ff126b 100644 --- a/src/Pusher/Http/Controllers/ChannelController.php +++ b/src/Pusher/Http/Controllers/ChannelController.php @@ -15,12 +15,8 @@ class ChannelController extends Controller */ public function handle(RequestInterface $request, Connection $connection, ...$args): Response { - if (! $channel = $args['channel'] ?? null) { - return new JsonResponse((object) []); - } - $info = explode(',', $this->query['info'] ?? ''); - $connections = $this->channels->channel(ChannelBroker::create($channel)); + $connections = $this->channels->channel(ChannelBroker::create($args['channel'])); $totalConnections = count($connections); return new JsonResponse((object) array_filter([ diff --git a/src/Pusher/Http/Controllers/ChannelUsersController.php b/src/Pusher/Http/Controllers/ChannelUsersController.php index fd924d14..7ef9974c 100644 --- a/src/Pusher/Http/Controllers/ChannelUsersController.php +++ b/src/Pusher/Http/Controllers/ChannelUsersController.php @@ -2,17 +2,26 @@ namespace Laravel\Reverb\Pusher\Http\Controllers; +use Laravel\Reverb\Channels\ChannelBroker; +use Laravel\Reverb\Channels\PresenceChannel; use Laravel\Reverb\Http\Connection; use Psr\Http\Message\RequestInterface; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; class ChannelUsersController extends Controller { /** * Handle the request. */ - public function handle(RequestInterface $request, Connection $connection, ...$args) + public function handle(RequestInterface $request, Connection $connection, ...$args): Response { + $channel = ChannelBroker::create($args['channel']); + + if(! $channel instanceof PresenceChannel) { + return new JsonResponse((object) [], 400); + } + return new JsonResponse((object) []); } } diff --git a/src/Servers/Reverb/Factory.php b/src/Servers/Reverb/Factory.php index e43887d4..5894b658 100644 --- a/src/Servers/Reverb/Factory.php +++ b/src/Servers/Reverb/Factory.php @@ -44,7 +44,7 @@ protected static function routes(): RouteCollection $routes->add('events_batch', Route::post('/apps/{appId}/batch_events', new EventsBatchController)); $routes->add('channels', Route::get('/apps/{appId}/channels', new ChannelsController)); $routes->add('channel', Route::get('/apps/{appId}/channels/{channel}', new ChannelController)); - // $routes->add('channel_users', Route::post('/apps/{appId}/channels/{channel}/users', new ChannelUsersController)); + $routes->add('channel_users', Route::get('/apps/{appId}/channels/{channel}/users', new ChannelUsersController)); // $routes->add('users_terminate', Route::post('/apps/{appId}/users/{user}/terminate_connections', new UsersTerminateController)); return $routes; diff --git a/tests/Feature/Ratchet/ChannelUsersControllerTest.php b/tests/Feature/Ratchet/ChannelUsersControllerTest.php new file mode 100644 index 00000000..efc141eb --- /dev/null +++ b/tests/Feature/Ratchet/ChannelUsersControllerTest.php @@ -0,0 +1,16 @@ +signedRequest('channels/test-channel/users')); +})->throws(ResponseException::class); + +it('returns the user data', function () { + // +})->todo();