add enable_client_messages

This commit is contained in:
freek 2018-12-01 15:47:55 +01:00
parent d7c6321d51
commit 99693249ba
3 changed files with 34 additions and 6 deletions

View File

@ -7,13 +7,17 @@ return [
* configure the different apps that can use the webSockets server. * configure the different apps that can use the webSockets server.
* *
* You should make sure that the app id is numeric. * 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' => [ 'apps' => [
[ [
'id' => env('PUSHER_APP_ID'), 'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'), 'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'), 'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET') 'secret' => env('PUSHER_APP_SECRET'),
'enable_client_messages' => true,
], ],
], ],

View File

@ -18,6 +18,9 @@ class App
/** @var string|null */ /** @var string|null */
public $name; public $name;
/** @var bool */
public $clientMessagesEnabled = false;
public static function findById(int $appId) public static function findById(int $appId)
{ {
return app(AppProvider::class)->findById($appId); return app(AppProvider::class)->findById($appId);
@ -28,7 +31,7 @@ class App
return app(AppProvider::class)->findByKey($appKey); 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)) { if (!is_numeric($appId)) {
throw InvalidApp::appIdIsNotNumeric($appId); throw InvalidApp::appIdIsNotNumeric($appId);
@ -47,7 +50,19 @@ class App
$this->key = $appKey; $this->key = $appKey;
$this->secret = $appSecret; $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;
} }
} }

View File

@ -48,11 +48,20 @@ class ConfigAppProvider implements AppProvider
return null; return null;
} }
return new App( $app = new App(
$appAttributes['id'], $appAttributes['id'],
$appAttributes['key'], $appAttributes['key'],
$appAttributes['secret'], $appAttributes['secret']
$appAttributes['name'] ?? null
); );
if (isset($appAttributes['name'])) {
$app->setName($appAttributes['name']);
}
if ($appAttributes['enable_client_messages'] ?? false) {
$app->enableClientMessages();
}
return $app;
} }
} }