From 84b8895ff82e1ea3e6a945dd33c2ec758557feb0 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Mon, 3 Dec 2018 22:59:50 +0100 Subject: [PATCH] wip --- resources/views/dashboard.blade.php | 26 ++++++++++++++++++- .../Controllers/DashboardApiController.php | 23 ++++++++++++++++ src/WebSocketsServiceProvider.php | 2 ++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/Dashboard/Http/Controllers/DashboardApiController.php diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 906db2a..28521a6 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -4,12 +4,15 @@ WebSockets Dashboard + - + + + @@ -33,6 +36,9 @@
+
+ +

Event Creator

@@ -88,6 +94,7 @@ data: { connected: false, + chart: null, pusher: null, port: 6001, app: null, @@ -121,6 +128,8 @@ this.pusher.connection.bind('connected', () => { this.connected = true; + + this.loadChart(); }); this.pusher.connection.bind('disconnected', () => { @@ -135,6 +144,21 @@ this.pusher.disconnect(); }, + loadChart() { + $.getJSON('/{{ request()->path() }}/api/'+this.app.id+'/statistics', (data) => { + this.chart = $('#statisticsChart').epoch({ + type: 'time.line', + axes: ['left', 'right', 'bottom'], + data: [ + { + label: "Peak Connections", + values: data.peak_connections, + } + ] + }); + }); + }, + subscribeToAllChannels() { [ 'disconnection', diff --git a/src/Dashboard/Http/Controllers/DashboardApiController.php b/src/Dashboard/Http/Controllers/DashboardApiController.php new file mode 100644 index 0000000..b406503 --- /dev/null +++ b/src/Dashboard/Http/Controllers/DashboardApiController.php @@ -0,0 +1,23 @@ +latest()->limit(120)->get(); + + $peakConnections = $statistics->map(function ($statistic) { + return [ + 'time' => $statistic->created_at->timestamp, + 'y' => $statistic->peak_connection_count + ]; + })->reverse()->values(); + + return [ + 'peak_connections' => $peakConnections + ]; + } +} \ No newline at end of file diff --git a/src/WebSocketsServiceProvider.php b/src/WebSocketsServiceProvider.php index 338c5c6..be699c7 100644 --- a/src/WebSocketsServiceProvider.php +++ b/src/WebSocketsServiceProvider.php @@ -3,6 +3,7 @@ namespace BeyondCode\LaravelWebSockets; use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard; +use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController; use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage; use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard; use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize; @@ -65,6 +66,7 @@ class WebSocketsServiceProvider extends ServiceProvider 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); });