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

Commit fd2203c

Browse files
committed
wip
1 parent 6c96bb8 commit fd2203c

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

config/websockets.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,19 @@
4242
*/
4343
'max_request_size_in_kb' => 250,
4444

45-
/*
46-
* This model will be used to store the statistics of the WebSocketsServer
47-
*/
48-
'statistics_model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
45+
'statistics' => [
46+
/*
47+
* This model will be used to store the statistics of the WebSocketsServer.
48+
* The only requirement is that the model should be or extend
49+
* `WebSocketsStatisticsEntry` provided by this package.
50+
*/
51+
'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
52+
53+
/*
54+
* Here you can specify the interval in seconds at which statistics should be logged.
55+
*/
56+
'interval_in_seconds' => 60,
57+
],
4958

5059
/*
5160
* Define the optional SSL context for your WebSocket connections.

src/Console/StartWebSocketServer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function configureStatisticsLogger()
5757
return new HttpStatisticsLogger(app(ChannelManager::class), $browser);
5858
});
5959

60-
$this->loop->addPeriodicTimer(5, function() {
60+
$this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function() {
6161
StatisticsLogger::save();
6262
});
6363

src/Statistics/Events/StatisticsUpdated.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BeyondCode\LaravelWebsockets\Statistics\Events;
44

55
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
6+
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
67
use Illuminate\Broadcasting\PrivateChannel;
78
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
89
use Illuminate\Queue\SerializesModels;
@@ -11,27 +12,30 @@ class StatisticsUpdated implements ShouldBroadcast
1112
{
1213
use SerializesModels;
1314

14-
protected $statisticModel;
15+
/** @var \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry */
16+
protected $webSocketsStatisticsEntry;
1517

16-
public function __construct($statisticModel)
18+
public function __construct(WebSocketsStatisticsEntry $webSocketsStatisticsEntry)
1719
{
18-
$this->statisticModel = $statisticModel;
20+
$this->webSocketsStatisticsEntry = $webSocketsStatisticsEntry;
1921
}
2022

2123
public function broadcastWith()
2224
{
2325
return [
24-
'time' => $this->statisticModel->created_at->timestamp,
25-
'app_id' => $this->statisticModel->appId,
26-
'peak_connection_count' => $this->statisticModel->peakConnectionCount,
27-
'websocket_message_count' => $this->statisticModel->webSocketMessageCount,
28-
'api_message_count' => $this->statisticModel->apiMessageCount,
26+
'time' => $this->webSocketsStatisticsEntry->created_at->timestamp,
27+
'app_id' => $this->webSocketsStatisticsEntry->appId,
28+
'peak_connection_count' => $this->webSocketsStatisticsEntry->peakConnectionCount,
29+
'websocket_message_count' => $this->webSocketsStatisticsEntry->webSocketMessageCount,
30+
'api_message_count' => $this->webSocketsStatisticsEntry->apiMessageCount,
2931
];
3032
}
3133

3234
public function broadcastOn()
3335
{
34-
return new PrivateChannel(str_after(DashboardLogger::LOG_CHANNEL_PREFIX . 'statistics', 'private-'));
36+
$channelName = str_after(DashboardLogger::LOG_CHANNEL_PREFIX . 'statistics', 'private-');
37+
38+
return new PrivateChannel($channelName);
3539
}
3640

3741
public function broadcastAs()

src/Statistics/Http/Controllers/WebSocketStatisticsEntriesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function store(Request $request)
1717
'api_message_count' => 'required|integer',
1818
]);
1919

20-
$webSocketsStatisticsEntryModelClass = config('websockets.statistics_model');
20+
$webSocketsStatisticsEntryModelClass = config('websockets.statistics.model');
2121

2222
$statisticModel = $webSocketsStatisticsEntryModelClass::create($validatedAttributes);
2323

0 commit comments

Comments
 (0)