Skip to content

[12.x] Add sockudo support as broadcasting driver #55808

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

Draft
wants to merge 4 commits into
base: 12.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions config/broadcasting.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@
],
],

'sockudo' => [
'driver' => 'reverb',
'key' => env('SOCKUDO_APP_KEY'),
'secret' => env('SOCKUDO_APP_SECRET'),
'app_id' => env('SOCKUDO_APP_ID'),
'options' => [
'host' => env('SOCKUDO_HOST'),
'port' => env('SOCKUDO_PORT', 443),
'scheme' => env('SOCKUDO_SCHEME', 'https'),
'useTLS' => env('SOCKUDO_SCHEME', 'https') === 'https',
],
'client_options' => [
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
],
],

'ably' => [
'driver' => 'ably',
'key' => env('ABLY_KEY'),
Expand Down
31 changes: 31 additions & 0 deletions src/Illuminate/Foundation/Console/BroadcastingInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BroadcastingInstallCommand extends Command
{--reverb : Install Laravel Reverb as the default broadcaster}
{--pusher : Install Pusher as the default broadcaster}
{--ably : Install Ably as the default broadcaster}
{--sockudo: Install Sockudo as the default broadcaster}
{--without-node : Do not prompt to install Node dependencies}';

/**
Expand Down Expand Up @@ -207,6 +208,7 @@ protected function collectDriverConfig()
match ($this->driver) {
'pusher' => $this->collectPusherConfig(),
'ably' => $this->collectAblyConfig(),
'sockudo' => $this->collectSockudoConfig(),
default => null,
};
}
Expand Down Expand Up @@ -289,6 +291,30 @@ protected function collectAblyConfig()
], $this->laravel->basePath('.env'));
}

/**
* Collect the Sockudo configuration.
*
* @return void
*/
protected function collectSockudoConfig()
{
$appId = text('Sockudo App ID', 'Enter your Pusher app ID');
$key = password('Sockudo App Key', 'Enter your Pusher app key');
$secret = password('Sockudo App Secret', 'Enter your Pusher app secret');

Env::writeVariables([
'SOCKUDO_APP_ID' => $appId,
'SOCKUDO_APP_KEY' => $key,
'SOCKUDO_APP_SECRET' => $secret,
'SOCKUDO_PORT' => 443,
'SOCKUDO_SCHEME' => 'https',
'VITE_SOCKUDO_APP_KEY' => '${SOCKUDO_APP_KEY}',
'VITE_SOCKUDO_HOST' => '${SOCKUDO_HOST}',
'VITE_SOCKUDO' => '${SOCKUDO_PORT}',
'VITE_SOCKUDO_SCHEME' => '${SOCKUDO_SCHEME}',
], $this->laravel->basePath('.env'));
}

/**
* Inject Echo configuration into the application's main file.
*
Expand Down Expand Up @@ -460,10 +486,15 @@ protected function resolveDriver(): string
return 'ably';
}

if ($this->option('sockudo')) {
return 'sockudo';
}

return select('Which broadcasting driver would you like to use?', [
'reverb' => 'Laravel Reverb',
'pusher' => 'Pusher',
'ably' => 'Ably',
'sockudo' => 'Sockudo',
]);
}

Expand Down
14 changes: 14 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/echo-js-sockudo.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Echo from 'laravel-echo';

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

window.Echo = new Echo({
broadcaster: 'sockudo',
key: import.meta.env.VITE_SOCKUDO_APP_KEY,
wsHost: import.meta.env.VITE_SOCKUDO_HOST,
wsPort: import.meta.env.VITE_SOCKUDO_PORT ?? 80,
wssPort: import.meta.env.VITE_SOCKUDO_PORT ?? 443,
forceTLS: (import.meta.env.VITE_SOCKUDO_SCHEME ?? 'https') === 'https',
enabledTransports: ['ws', 'wss'],
});