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

Commit 99b5541

Browse files
committed
Removed controller that sends out the statistics
1 parent ed96e24 commit 99b5541

9 files changed

+23
-189
lines changed

config/websockets.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -239,37 +239,6 @@
239239

240240
'delete_statistics_older_than_days' => 60,
241241

242-
/*
243-
|--------------------------------------------------------------------------
244-
| DNS Lookup
245-
|--------------------------------------------------------------------------
246-
|
247-
| Use an DNS resolver to make the requests to the statistics logger
248-
| default is to resolve everything to 127.0.0.1.
249-
|
250-
*/
251-
252-
'perform_dns_lookup' => false,
253-
254-
/*
255-
|--------------------------------------------------------------------------
256-
| DNS Lookup TLS Settings
257-
|--------------------------------------------------------------------------
258-
|
259-
| You can configure the DNS Lookup Connector the TLS settings.
260-
| Check the available options here:
261-
| https://github.com/reactphp/socket/blob/master/src/Connector.php#L29
262-
|
263-
*/
264-
265-
'tls' => [
266-
267-
'verify_peer' => env('APP_ENV') === 'production',
268-
269-
'verify_peer_name' => env('APP_ENV') === 'production',
270-
271-
],
272-
273242
],
274243

275244
];

src/Console/StartWebSocketServer.php

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
1313
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
1414
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
15+
use BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver;
1516
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
1617
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
1718
use Clue\React\Buzz\Browser;
@@ -103,19 +104,12 @@ public function handle()
103104
*/
104105
protected function configureStatisticsLogger()
105106
{
106-
$connector = new Connector($this->loop, [
107-
'dns' => $this->getDnsResolver(),
108-
'tls' => config('websockets.statistics.tls'),
109-
]);
110-
111-
$browser = new Browser($this->loop, $connector);
112-
113-
$this->laravel->singleton(StatisticsLoggerInterface::class, function () use ($browser) {
107+
$this->laravel->singleton(StatisticsLoggerInterface::class, function () {
114108
$class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class);
115109

116110
return new $class(
117111
$this->laravel->make(ChannelManager::class),
118-
$browser
112+
$this->laravel->make(StatisticsDriver::class)
119113
);
120114
});
121115

@@ -273,27 +267,6 @@ protected function buildServer()
273267
->createServer();
274268
}
275269

276-
/**
277-
* Create a DNS resolver for the stats manager.
278-
*
279-
* @return \React\Dns\Resolver\ResolverInterface
280-
*/
281-
protected function getDnsResolver(): ResolverInterface
282-
{
283-
if (! config('websockets.statistics.perform_dns_lookup')) {
284-
return new DnsResolver;
285-
}
286-
287-
$dnsConfig = DnsConfig::loadSystemConfigBlocking();
288-
289-
return (new DnsFactory)->createCached(
290-
$dnsConfig->nameservers
291-
? reset($dnsConfig->nameservers)
292-
: '1.1.1.1',
293-
$this->loop
294-
);
295-
}
296-
297270
/**
298271
* Get the last time the server restarted.
299272
*

src/Statistics/Http/Controllers/WebSocketStatisticsEntriesController.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Statistics/Http/Middleware/Authorize.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Statistics/Logger/MemoryStatisticsLogger.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace BeyondCode\LaravelWebSockets\Statistics\Logger;
44

55
use BeyondCode\LaravelWebSockets\Apps\App;
6+
use BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver;
7+
use BeyondCode\LaravelWebSockets\Statistics\Events\StatisticsUpdated;
68
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
79
use BeyondCode\LaravelWebSockets\Statistics\Statistic;
810
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
@@ -27,23 +29,23 @@ class MemoryStatisticsLogger implements StatisticsLogger
2729
protected $channelManager;
2830

2931
/**
30-
* The Browser instance.
32+
* The statistics driver instance.
3133
*
32-
* @var \Clue\React\Buzz\Browser
34+
* @var \BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver
3335
*/
34-
protected $browser;
36+
protected $driver;
3537

3638
/**
3739
* Initialize the logger.
3840
*
3941
* @param \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager $channelManager
40-
* @param \Clue\React\Buzz\Browser $browser
42+
* @param \BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver $driver
4143
* @return void
4244
*/
43-
public function __construct(ChannelManager $channelManager, Browser $browser)
45+
public function __construct(ChannelManager $channelManager, StatisticsDriver $driver)
4446
{
4547
$this->channelManager = $channelManager;
46-
$this->browser = $browser;
48+
$this->driver = $driver;
4749
}
4850

4951
/**
@@ -106,16 +108,9 @@ public function save()
106108
continue;
107109
}
108110

109-
$postData = array_merge($statistic->toArray(), [
110-
'secret' => App::findById($appId)->secret,
111-
]);
112-
113-
$this->browser
114-
->post(
115-
action([WebSocketStatisticsEntriesController::class, 'store']),
116-
['Content-Type' => 'application/json'],
117-
stream_for(json_encode($postData))
118-
);
111+
broadcast(new StatisticsUpdated(
112+
$this->driver::create($statistic->toArray())
113+
));
119114

120115
$currentConnectionCount = $this->channelManager->getConnectionCount($appId);
121116

src/Statistics/Logger/NullStatisticsLogger.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
66
use Clue\React\Buzz\Browser;
77
use Ratchet\ConnectionInterface;
8+
use BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver;
89

910
class NullStatisticsLogger implements StatisticsLogger
1011
{
@@ -16,23 +17,23 @@ class NullStatisticsLogger implements StatisticsLogger
1617
protected $channelManager;
1718

1819
/**
19-
* The Browser instance.
20+
* The statistics driver instance.
2021
*
21-
* @var \Clue\React\Buzz\Browser
22+
* @var \BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver
2223
*/
23-
protected $browser;
24+
protected $driver;
2425

2526
/**
2627
* Initialize the logger.
2728
*
2829
* @param \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager $channelManager
29-
* @param \Clue\React\Buzz\Browser $browser
30+
* @param \BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver $driver
3031
* @return void
3132
*/
32-
public function __construct(ChannelManager $channelManager, Browser $browser)
33+
public function __construct(ChannelManager $channelManager, StatisticsDriver $driver)
3334
{
3435
$this->channelManager = $channelManager;
35-
$this->browser = $browser;
36+
$this->driver = $driver;
3637
}
3738

3839
/**

src/WebSocketsServiceProvider.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use BeyondCode\LaravelWebSockets\Server\Router;
1313
use BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver;
1414
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
15-
use BeyondCode\LaravelWebSockets\Statistics\Http\Middleware\Authorize as AuthorizeStatistics;
1615
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
1716
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers\ArrayChannelManager;
1817
use Illuminate\Broadcasting\BroadcastManager;
@@ -127,10 +126,6 @@ protected function registerDashboardRoutes()
127126
Route::post('auth', AuthenticateDashboard::class);
128127
Route::post('event', SendMessage::class);
129128
});
130-
131-
Route::middleware(AuthorizeStatistics::class)->group(function () {
132-
Route::post('statistics', [WebSocketStatisticsEntriesController::class, 'store']);
133-
});
134129
});
135130

136131
return $this;

tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/TestCase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use BeyondCode\LaravelWebSockets\PubSub\Drivers\LocalClient;
77
use BeyondCode\LaravelWebSockets\PubSub\Drivers\RedisClient;
88
use BeyondCode\LaravelWebSockets\PubSub\ReplicationInterface;
9+
use BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver;
910
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
1011
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
1112
use BeyondCode\LaravelWebSockets\Tests\Statistics\Logger\FakeStatisticsLogger;
@@ -45,7 +46,7 @@ public function setUp(): void
4546

4647
StatisticsLogger::swap(new FakeStatisticsLogger(
4748
$this->channelManager,
48-
Mockery::mock(Browser::class)
49+
app(StatisticsDriver::class)
4950
));
5051

5152
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
@@ -94,8 +95,6 @@ protected function getEnvironmentSetUp($app)
9495
],
9596
]);
9697

97-
$app['config']->set('websockets.statistics.perform_dns_lookup', true);
98-
9998
$app['config']->set('database.redis.default', [
10099
'host' => env('REDIS_HOST', '127.0.0.1'),
101100
'password' => env('REDIS_PASSWORD', null),

0 commit comments

Comments
 (0)