Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Allow install:broadcasting to populate echo.js configuration either with or without Reverb #50455

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/Illuminate/Foundation/Console/BroadcastingInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Process\PhpExecutableFinder;

use function Illuminate\Filesystem\join_paths;
use function Laravel\Prompts\confirm;

#[AsCommand(name: 'install:broadcasting')]
Expand Down Expand Up @@ -53,9 +54,11 @@ public function handle()
$this->uncommentChannelsRoutesFile();
}

$installReverb = $this->shouldInstallReverb();

// Install bootstrapping...
if (! file_exists($echoScriptPath = $this->laravel->resourcePath('js/echo.js'))) {
copy(__DIR__.'/stubs/echo-js.stub', $echoScriptPath);
copy(join_paths(__DIR__, 'stubs', $installReverb ? 'echo-js.stub' : 'echo.js.pusher.stub'), $echoScriptPath);
}

if (file_exists($bootstrapScriptPath = $this->laravel->resourcePath('js/bootstrap.js'))) {
Expand All @@ -71,7 +74,9 @@ public function handle()
}
}

$this->installReverb();
if ($installReverb) {
$this->performReverbInstallation();
}

$this->installNodeDependencies();
}
Expand Down Expand Up @@ -111,18 +116,12 @@ protected function uncommentChannelsRoutesFile()
*
* @return void
*/
protected function installReverb()
protected function performReverbInstallation()
{
if (InstalledVersions::isInstalled('laravel/reverb')) {
return;
}

$install = confirm('Would you like to install Laravel Reverb?', default: true);

if (! $install) {
return;
}

$this->requireComposerPackages($this->option('composer'), [
'laravel/reverb:@beta',
]);
Expand All @@ -138,6 +137,20 @@ protected function installReverb()
$this->components->info('Reverb installed successfully.');
}

/**
* Determine if Reverb should be installed.
*
* @return bool
*/
public function shouldInstallReverb()
{
if (InstalledVersions::isInstalled('laravel/reverb')) {
return true;
}

return confirm('Would you like to install Laravel Reverb?', default: true);
}

/**
* Install and build Node dependencies.
*
Expand Down
15 changes: 15 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/echo-js.pusher.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Echo from 'laravel-echo';

import Pusher from 'pusher-js';
window.Pusher = Pusher;

window.Echo = new Echo({
broadcaster: 'pusher',
key: import.meta.env.VITE_PUSHER_APP_KEY,
cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER ?? 'mt1',
wsHost: import.meta.env.VITE_PUSHER_HOST ? import.meta.env.VITE_PUSHER_HOST : `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`,
wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80,
wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443,
forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https',
enabledTransports: ['ws', 'wss'],
});
Loading