Skip to content

Commit

Permalink
Generate the Echo config in PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Mar 19, 2024
1 parent e528507 commit e669386
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
5 changes: 1 addition & 4 deletions resources/js/components/Echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class Echo {

start() {
let config = {
broadcaster: 'pusher',
key: Statamic.$config.get('broadcasting.pusher.key'),
cluster: Statamic.$config.get('broadcasting.pusher.cluster'),
encrypted: Statamic.$config.get('broadcasting.pusher.encrypted'),
...Statamic.$config.get('broadcasting.options'),
csrfToken: Statamic.$config.get('csrfToken'),
authEndpoint: Statamic.$config.get('broadcasting.endpoint'),
};
Expand Down
33 changes: 25 additions & 8 deletions src/Providers/BroadcastServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,34 @@ public function boot()

protected function variables()
{
return [
'enabled' => true,
'endpoint' => $this->authEndpoint(),
'pusher' => [
$options = [];

if (config('broadcasting.default') === 'pusher') {
$options = [
'broadcaster' => 'pusher',
'key' => config('broadcasting.connections.pusher.key'),
'cluster' => config('broadcasting.connections.pusher.options.cluster'),
'encrypted' => config('broadcasting.connections.pusher.options.encrypted'),
'scheme' => config('broadcasting.connections.pusher.options.scheme'),
'host' => config('broadcasting.connections.pusher.options.host'),
'port' => config('broadcasting.connections.pusher.options.port'),
],
];
}

if (config('broadcasting.default') === 'reverb') {
$options = [
'broadcaster' => 'reverb',
'key' => config('broadcasting.connections.reverb.key'),
'wsHost' => config('broadcasting.connections.reverb.options.host'),
'wsPort' => config('broadcasting.connections.reverb.options.port', 80),
'wssPort' => config('broadcasting.connections.reverb.options.port', 443),
'forceTLS' => config('broadcasting.connections.reverb.options.useTLS'),
'enabledTransports' => ['ws', 'wss'],
];
}

return [
'enabled' => true,
'endpoint' => $this->authEndpoint(),
'connection' => config('broadcasting.default'),
'options' => $options,
];
}

Expand Down

0 comments on commit e669386

Please sign in to comment.