From 99693249ba4ad1b3dcd944e48a7e83dff04560e5 Mon Sep 17 00:00:00 2001 From: freek Date: Sat, 1 Dec 2018 15:47:55 +0100 Subject: [PATCH] add enable_client_messages --- config/websockets.php | 6 +++++- src/Apps/App.php | 19 +++++++++++++++++-- src/Apps/ConfigAppProvider.php | 15 ++++++++++++--- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/config/websockets.php b/config/websockets.php index 7175e80..ceeb677 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -7,13 +7,17 @@ return [ * configure the different apps that can use the webSockets server. * * You should make sure that the app id is numeric. + * + * Optionally you can disable client events so clients cannot send + * messages through each other via the webSockets. */ 'apps' => [ [ 'id' => env('PUSHER_APP_ID'), 'name' => env('APP_NAME'), 'key' => env('PUSHER_APP_KEY'), - 'secret' => env('PUSHER_APP_SECRET') + 'secret' => env('PUSHER_APP_SECRET'), + 'enable_client_messages' => true, ], ], diff --git a/src/Apps/App.php b/src/Apps/App.php index b569e0a..0b8e836 100644 --- a/src/Apps/App.php +++ b/src/Apps/App.php @@ -18,6 +18,9 @@ class App /** @var string|null */ public $name; + /** @var bool */ + public $clientMessagesEnabled = false; + public static function findById(int $appId) { return app(AppProvider::class)->findById($appId); @@ -28,7 +31,7 @@ class App return app(AppProvider::class)->findByKey($appKey); } - public function __construct($appId, string $appKey, string $appSecret, ?string $name) + public function __construct($appId, string $appKey, string $appSecret) { if (!is_numeric($appId)) { throw InvalidApp::appIdIsNotNumeric($appId); @@ -47,7 +50,19 @@ class App $this->key = $appKey; $this->secret = $appSecret; + } - $this->name = $name; + public function setName(string $appName) + { + $this->name = $appName; + + return $this; + } + + public function enableClientMessages(bool $enabled = true) + { + $this->clientMessagesEnabled = $enabled; + + return $this; } } diff --git a/src/Apps/ConfigAppProvider.php b/src/Apps/ConfigAppProvider.php index 5977416..3ee0ad4 100644 --- a/src/Apps/ConfigAppProvider.php +++ b/src/Apps/ConfigAppProvider.php @@ -48,11 +48,20 @@ class ConfigAppProvider implements AppProvider return null; } - return new App( + $app = new App( $appAttributes['id'], $appAttributes['key'], - $appAttributes['secret'], - $appAttributes['name'] ?? null + $appAttributes['secret'] ); + + if (isset($appAttributes['name'])) { + $app->setName($appAttributes['name']); + } + + if ($appAttributes['enable_client_messages'] ?? false) { + $app->enableClientMessages(); + } + + return $app; } } \ No newline at end of file