From 4aab3d441ff6c921c9c892f48de83e72b54009e1 Mon Sep 17 00:00:00 2001 From: freek Date: Tue, 4 Dec 2018 10:06:26 +0100 Subject: [PATCH 1/2] wip --- config/websockets.php | 5 +++++ src/WebSocketsServiceProvider.php | 24 +++++++----------------- tests/TestCase.php | 5 ----- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/config/websockets.php b/config/websockets.php index caa8507..0a0f060 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -56,6 +56,11 @@ return [ 'interval_in_seconds' => 60, ], + /* + * This path will be used to register the necessary routes for the package. + */ + 'path' => 'laravel-websockets', + /* * Define the optional SSL context for your WebSocket connections. * You can see all available options at: http://php.net/manual/en/context.ssl.php diff --git a/src/WebSocketsServiceProvider.php b/src/WebSocketsServiceProvider.php index 36afd03..7a43888 100644 --- a/src/WebSocketsServiceProvider.php +++ b/src/WebSocketsServiceProvider.php @@ -32,8 +32,7 @@ class WebSocketsServiceProvider extends ServiceProvider } $this - ->registerRouteMacro() - ->registerStatisticRoute() + ->registerRoutes() ->registerDashboardGate(); $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'websockets'); @@ -60,23 +59,14 @@ class WebSocketsServiceProvider extends ServiceProvider }); } - protected function registerRouteMacro() + protected function registerRoutes() { - Route::macro('webSockets', function ($prefix = 'laravel-websockets') { - Route::prefix($prefix)->namespace('\\')->middleware(Authorize::class)->group(function () { - Route::get('/', ShowDashboard::class); - Route::get('/api/{appId}/statistics', DashboardApiController::class . '@getStatistics'); - Route::post('auth', AuthenticateDashboard::class); - Route::post('event', SendMessage::class); - }); - }); + Route::prefix(config('websockets.path'))->middleware(Authorize::class)->group(function () { + Route::get('/', ShowDashboard::class); + Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']); + Route::post('auth', AuthenticateDashboard::class); + Route::post('event', SendMessage::class); - return $this; - } - - protected function registerStatisticRoute() - { - Route::prefix('/laravel-websockets')->namespace('\\')->group(function () { Route::post('statistics', [WebSocketStatisticsEntriesController::class, 'store']); }); diff --git a/tests/TestCase.php b/tests/TestCase.php index 96c0875..1a51144 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -29,11 +29,6 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase $this->channelManager = app(ChannelManager::class); - /** TODO: make this work without middleware prefix */ - Route::middleware('App\Http\Controllers')->group(function() { - Route::webSockets(); - }); - StatisticsLogger::fake(); } From a79179cef3bfdd90bc0d68d3f1482e48f4f6abce Mon Sep 17 00:00:00 2001 From: freek Date: Tue, 4 Dec 2018 10:11:53 +0100 Subject: [PATCH 2/2] wip --- src/WebSocketsServiceProvider.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/WebSocketsServiceProvider.php b/src/WebSocketsServiceProvider.php index 7a43888..6d3ed2e 100644 --- a/src/WebSocketsServiceProvider.php +++ b/src/WebSocketsServiceProvider.php @@ -61,11 +61,13 @@ class WebSocketsServiceProvider extends ServiceProvider protected function registerRoutes() { - Route::prefix(config('websockets.path'))->middleware(Authorize::class)->group(function () { - Route::get('/', ShowDashboard::class); - Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']); - Route::post('auth', AuthenticateDashboard::class); - Route::post('event', SendMessage::class); + Route::prefix(config('websockets.path'))->group(function() { + Route::middleware(Authorize::class)->group(function() { + Route::get('/', ShowDashboard::class); + Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']); + Route::post('auth', AuthenticateDashboard::class); + Route::post('event', SendMessage::class); + }); Route::post('statistics', [WebSocketStatisticsEntriesController::class, 'store']); });