Skip to content

Commit

Permalink
add reverb broadcasting config (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon authored Feb 23, 2024
1 parent f7fc475 commit dc7fae3
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function handle(): void
{
$this->addEnviromentVariables();
$this->publishConfiguration();
$this->updateBroadcastingConfiguration();
$this->enableBroadcasting();
$this->updateBroadcastingDriver();

Expand Down Expand Up @@ -91,6 +92,45 @@ protected function publishConfiguration(): void
]);
}

/**
* Update the broadcasting.php configuration file.
*/
protected function updateBroadcastingConfiguration(): void
{
if (! $this->isLaravelTen()) {
return;
}

if ($this->laravel->config->has('broadcasting.connections.reverb')) {
return;
}

File::replaceInFile(
"'connections' => [\n",
<<<CONFIG
'connections' => [
'reverb' => [
'driver' => 'reverb',
'key' => env('REVERB_APP_KEY'),
'secret' => env('REVERB_APP_SECRET'),
'app_id' => env('REVERB_APP_ID'),
'options' => [
'host' => env('REVERB_HOST'),
'port' => env('REVERB_PORT', 443),
'scheme' => env('REVERB_SCHEME', 'https'),
'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
],
'client_options' => [
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
],
],
CONFIG,
app()->configPath('broadcasting.php')
);
}

/**
* Enable Laravel's broadcasting functionality.
*/
Expand All @@ -106,7 +146,7 @@ protected function enableBroadcasting(): void
return;
}

if (version_compare($this->laravel->version(), '11.0', '<')) {
if ($this->isLaravelTen()) {
$this->enableBroadcastServiceProvider();

return;
Expand Down Expand Up @@ -149,4 +189,12 @@ protected function updateBroadcastingDriver(): void
})
);
}

/**
* Determine if the application is using Laravel 10.
*/
protected function isLaravelTen(): bool
{
return version_compare($this->laravel->version(), '11.0', '<');
}
}

0 comments on commit dc7fae3

Please sign in to comment.