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

Commit 8bd50f0

Browse files
committed
wip
1 parent 8665193 commit 8bd50f0

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/Statistics/Logger/HttpStatisticsLogger.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
88
use Clue\React\Buzz\Browser;
99
use GuzzleHttp\Client;
10+
use function GuzzleHttp\Psr7\stream_for;
1011
use Ratchet\ConnectionInterface;
1112

1213
class HttpStatisticsLogger implements StatisticsLogger
@@ -67,24 +68,17 @@ public function save()
6768
echo 'in actual save method';
6869

6970
foreach ($this->statistics as $appId => $statistic) {
70-
echo "stats of ${appId} " . $statistic->isEnabled() ? 'enabled' : 'DISABLED!';
71+
7172
if (!$statistic->isEnabled()) {
7273
continue;
7374
}
7475

75-
echo 'posted';
7676
$this->browser
7777
->post(
7878
action([WebsocketStatisticsEntriesController::class, 'store']),
79-
[],
80-
$statistic->toArray()
81-
)
82-
->then(function() {
83-
echo 'fulfilled';
84-
}, function($e) {
85-
echo 'fulfilled';
86-
dd($);
87-
});
79+
['Content-Type' => 'application/json'],
80+
stream_for(json_encode($statistic->toArray()))
81+
);
8882

8983
// Reset connection and message count
9084
$currentConnectionCount = collect($this->channelManager->getChannels($appId))

src/WebSocketsServiceProvider.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
1515
use Illuminate\Support\ServiceProvider;
1616
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
17+
use Illuminate\Support\Str;
1718

1819
class WebSocketsServiceProvider extends ServiceProvider
1920
{
@@ -31,6 +32,8 @@ public function boot()
3132

3233
$this->registerRouteMacro();
3334

35+
$this->registerStatisticRoute();
36+
3437
$this->registerDashboardGate();
3538

3639
$this->loadViewsFrom(__DIR__.'/../resources/views/', 'websockets');
@@ -65,11 +68,13 @@ protected function registerRouteMacro()
6568
Route::post('auth', AuthenticateDashboard::class);
6669
Route::post('event', SendMessage::class);
6770
});
71+
});
72+
}
6873

69-
//TODO: add middleware
70-
Route::prefix($prefix)->namespace('\\')->group(function() {
71-
Route::post('statistics', [WebsocketStatisticsEntriesController::class, 'store']);
72-
});
74+
protected function registerStatisticRoute()
75+
{
76+
Route::prefix('/laravel-websockets')->namespace('\\')->group(function() {
77+
Route::post('statistics', [WebsocketStatisticsEntriesController::class, 'store']);
7378
});
7479
}
7580

0 commit comments

Comments
 (0)