From 8bd50f0e61ae81f31b2735d70ed73eb7dc349871 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Mon, 3 Dec 2018 21:41:41 +0100 Subject: [PATCH] wip --- src/Statistics/Logger/HttpStatisticsLogger.php | 16 +++++----------- src/WebSocketsServiceProvider.php | 13 +++++++++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Statistics/Logger/HttpStatisticsLogger.php b/src/Statistics/Logger/HttpStatisticsLogger.php index 8bc7261..13f881f 100644 --- a/src/Statistics/Logger/HttpStatisticsLogger.php +++ b/src/Statistics/Logger/HttpStatisticsLogger.php @@ -7,6 +7,7 @@ use BeyondCode\LaravelWebSockets\Statistics\Statistic; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; use Clue\React\Buzz\Browser; use GuzzleHttp\Client; +use function GuzzleHttp\Psr7\stream_for; use Ratchet\ConnectionInterface; class HttpStatisticsLogger implements StatisticsLogger @@ -67,24 +68,17 @@ class HttpStatisticsLogger implements StatisticsLogger echo 'in actual save method'; foreach ($this->statistics as $appId => $statistic) { - echo "stats of ${appId} " . $statistic->isEnabled() ? 'enabled' : 'DISABLED!'; + if (!$statistic->isEnabled()) { continue; } - echo 'posted'; $this->browser ->post( action([WebsocketStatisticsEntriesController::class, 'store']), - [], - $statistic->toArray() - ) - ->then(function() { - echo 'fulfilled'; - }, function($e) { - echo 'fulfilled'; - dd($); - }); + ['Content-Type' => 'application/json'], + stream_for(json_encode($statistic->toArray())) + ); // Reset connection and message count $currentConnectionCount = collect($this->channelManager->getChannels($appId)) diff --git a/src/WebSocketsServiceProvider.php b/src/WebSocketsServiceProvider.php index 8605499..338c5c6 100644 --- a/src/WebSocketsServiceProvider.php +++ b/src/WebSocketsServiceProvider.php @@ -14,6 +14,7 @@ use Illuminate\Support\Facades\Route; use BeyondCode\LaravelWebSockets\Apps\AppProvider; use Illuminate\Support\ServiceProvider; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; +use Illuminate\Support\Str; class WebSocketsServiceProvider extends ServiceProvider { @@ -31,6 +32,8 @@ class WebSocketsServiceProvider extends ServiceProvider $this->registerRouteMacro(); + $this->registerStatisticRoute(); + $this->registerDashboardGate(); $this->loadViewsFrom(__DIR__.'/../resources/views/', 'websockets'); @@ -65,11 +68,13 @@ class WebSocketsServiceProvider extends ServiceProvider Route::post('auth', AuthenticateDashboard::class); Route::post('event', SendMessage::class); }); + }); + } - //TODO: add middleware - Route::prefix($prefix)->namespace('\\')->group(function() { - Route::post('statistics', [WebsocketStatisticsEntriesController::class, 'store']); - }); + protected function registerStatisticRoute() + { + Route::prefix('/laravel-websockets')->namespace('\\')->group(function() { + Route::post('statistics', [WebsocketStatisticsEntriesController::class, 'store']); }); }