diff --git a/config/websockets.php b/config/websockets.php index 0e34006..63e1785 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -16,6 +16,7 @@ return [ 'key' => env('PUSHER_APP_KEY'), 'secret' => env('PUSHER_APP_SECRET'), 'enable_client_messages' => false, + 'enable_statistics' => true, ], ], diff --git a/database/migrations/create_websockets_statistics_entries_table.php.stub b/database/migrations/create_websockets_statistics_entries_table.php.stub new file mode 100644 index 0000000..3231f4a --- /dev/null +++ b/database/migrations/create_websockets_statistics_entries_table.php.stub @@ -0,0 +1,26 @@ +increments('id'); + $table->nullableTimestamps(); + }); + } + /** + * Reverse the migrations. + */ + public function down() + { + Schema::dropIfExists('websockets_statistics_entries'); + } +} diff --git a/src/Apps/App.php b/src/Apps/App.php index 1b279dc..ac484e6 100644 --- a/src/Apps/App.php +++ b/src/Apps/App.php @@ -21,6 +21,9 @@ class App /** @var bool */ public $clientMessagesEnabled = false; + /** @var bool */ + public $statisticsEnabled = true; + public static function findById($appId) { return app(AppProvider::class)->findById($appId); @@ -61,4 +64,11 @@ class App return $this; } + + public function enableStatistics(bool $enabled = true) + { + $this->statisticsEnabled = $enabled; + + return $this; + } } diff --git a/src/Apps/ConfigAppProvider.php b/src/Apps/ConfigAppProvider.php index 03754b4..78461f0 100644 --- a/src/Apps/ConfigAppProvider.php +++ b/src/Apps/ConfigAppProvider.php @@ -44,7 +44,7 @@ class ConfigAppProvider implements AppProvider protected function instanciate(?array $appAttributes): ?App { - if (! $appAttributes) { + if (!$appAttributes) { return null; } @@ -58,9 +58,10 @@ class ConfigAppProvider implements AppProvider $app->setName($appAttributes['name']); } - if ($appAttributes['enable_client_messages'] ?? false) { - $app->enableClientMessages(); - } + $app + ->enableClientMessages($appAttributes['enable_client_messages']) + ->enableStatistics($appAttributes['enable_statistics']); + return $app; } diff --git a/src/Statistics/WebSocketsStatisticsEntry.php b/src/Statistics/WebSocketsStatisticsEntry.php new file mode 100644 index 0000000..2569306 --- /dev/null +++ b/src/Statistics/WebSocketsStatisticsEntry.php @@ -0,0 +1,12 @@ + base_path('config/websockets.php'), ], 'config'); + if (! class_exists('CreateWebSocketsStatisticsEntries')) { + $this->publishes([ + __DIR__.'/../database/migrations/cretae_websockets_statistics_entries_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_cretae_websockets_statistics_entries_table.php'), + ], 'migrations'); + } + $this->registerRouteMacro(); $this->registerDashboardGate(); diff --git a/tests/ClientProviders/ConfigAppProviderTest.php b/tests/ClientProviders/ConfigAppProviderTest.php index 84182d0..4fedcdc 100644 --- a/tests/ClientProviders/ConfigAppProviderTest.php +++ b/tests/ClientProviders/ConfigAppProviderTest.php @@ -32,5 +32,6 @@ class ConfigAppProviderTest extends TestCase $this->assertEquals('TestKey', $app->key); $this->assertEquals('TestSecret', $app->secret); $this->assertFalse($app->clientMessagesEnabled); + $this->assertTrue($app->statisticsEnabled); } } \ No newline at end of file diff --git a/tests/Messages/PusherClientMessageTest.php b/tests/Messages/PusherClientMessageTest.php index 16ecccc..88b9e55 100644 --- a/tests/Messages/PusherClientMessageTest.php +++ b/tests/Messages/PusherClientMessageTest.php @@ -35,6 +35,7 @@ class PusherClientMessageTest extends TestCase 'key' => 'TestKey', 'secret' => 'TestSecret', 'enable_client_messages' => true, + 'enable_statistics' => true, ], ]); diff --git a/tests/TestCase.php b/tests/TestCase.php index 07a3e3e..c4e10b1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -41,6 +41,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase 'key' => 'TestKey', 'secret' => 'TestSecret', 'enable_client_messages' => false, + 'enable_statistics' => true, ], ]); }