Skip to content

Commit

Permalink
implements users routes
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Nov 19, 2023
1 parent 2ea636d commit 35336c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/Pusher/Http/Controllers/ChannelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
11 changes: 10 additions & 1 deletion src/Pusher/Http/Controllers/ChannelUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) []);
}
}
2 changes: 1 addition & 1 deletion src/Servers/Reverb/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions tests/Feature/Ratchet/ChannelUsersControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Laravel\Reverb\Tests\RatchetTestCase;
use React\Http\Message\ResponseException;

use function React\Async\await;

uses(RatchetTestCase::class);

it('returns an error when presence channel not provided', function () {
await($this->signedRequest('channels/test-channel/users'));
})->throws(ResponseException::class);

it('returns the user data', function () {
//
})->todo();

0 comments on commit 35336c7

Please sign in to comment.