Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 84b8895

Browse files
committed
wip
1 parent 533f8a5 commit 84b8895

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

resources/views/dashboard.blade.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
<title>WebSockets Dashboard</title>
55
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"
66
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
7+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/epoch/0.8.4/css/epoch.min.css" />
78
<script
89
src="https://code.jquery.com/jquery-3.3.1.min.js"
910
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
1011
crossorigin="anonymous"></script>
11-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
1212
<script src="https://js.pusher.com/4.3/pusher.min.js"></script>
13+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
14+
<script src="http://d3js.org/d3.v3.js" charset="utf-8"></script>
15+
<script src="https://cdnjs.cloudflare.com/ajax/libs/epoch/0.8.4/js/epoch.min.js"></script>
1316
</head>
1417

1518
<body>
@@ -33,6 +36,9 @@
3336
<div id="status"></div>
3437
</div>
3538
<div class="card-body">
39+
<div v-if="connected" id="statisticsChart" style="width: 100%; height: 250px;">
40+
41+
</div>
3642
<div v-if="connected">
3743
<h4>Event Creator</h4>
3844
<form>
@@ -88,6 +94,7 @@
8894
8995
data: {
9096
connected: false,
97+
chart: null,
9198
pusher: null,
9299
port: 6001,
93100
app: null,
@@ -121,6 +128,8 @@
121128
122129
this.pusher.connection.bind('connected', () => {
123130
this.connected = true;
131+
132+
this.loadChart();
124133
});
125134
126135
this.pusher.connection.bind('disconnected', () => {
@@ -135,6 +144,21 @@
135144
this.pusher.disconnect();
136145
},
137146
147+
loadChart() {
148+
$.getJSON('/{{ request()->path() }}/api/'+this.app.id+'/statistics', (data) => {
149+
this.chart = $('#statisticsChart').epoch({
150+
type: 'time.line',
151+
axes: ['left', 'right', 'bottom'],
152+
data: [
153+
{
154+
label: "Peak Connections",
155+
values: data.peak_connections,
156+
}
157+
]
158+
});
159+
});
160+
},
161+
138162
subscribeToAllChannels() {
139163
[
140164
'disconnection',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
4+
5+
class DashboardApiController
6+
{
7+
public function getStatistics($appId)
8+
{
9+
$webSocketsStatisticsEntryModelClass = config('websockets.statistics_model');
10+
$statistics = $webSocketsStatisticsEntryModelClass::where('app_id', $appId)->latest()->limit(120)->get();
11+
12+
$peakConnections = $statistics->map(function ($statistic) {
13+
return [
14+
'time' => $statistic->created_at->timestamp,
15+
'y' => $statistic->peak_connection_count
16+
];
17+
})->reverse()->values();
18+
19+
return [
20+
'peak_connections' => $peakConnections
21+
];
22+
}
23+
}

src/WebSocketsServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BeyondCode\LaravelWebSockets;
44

55
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
6+
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController;
67
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
78
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard;
89
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize;
@@ -65,6 +66,7 @@ protected function registerRouteMacro()
6566
Route::macro('webSockets', function($prefix = 'laravel-websockets') {
6667
Route::prefix($prefix)->namespace('\\')->middleware(Authorize::class)->group(function() {
6768
Route::get('/', ShowDashboard::class);
69+
Route::get('/api/{appId}/statistics', DashboardApiController::class.'@getStatistics');
6870
Route::post('auth', AuthenticateDashboard::class);
6971
Route::post('event', SendMessage::class);
7072
});

0 commit comments

Comments
 (0)