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

[4.x] Allow custom Echo client configuration #9464

Merged
merged 4 commits into from Feb 6, 2024

Conversation

jacksleight
Copy link
Contributor

@jacksleight jacksleight commented Feb 6, 2024

This PR allows you to use a custom broadcasting Echo client config within the CP.

It adds a new Statamic.$echo.config() method and passes some additional pusher options through to the JS side.

For example to use with Soketi add this to cp.js:

Statamic.booting(() => {
    
    Statamic.$echo.config(() => ({
        broadcaster: "pusher",
        key: Statamic.$config.get('broadcasting.pusher.key'),
        cluster: Statamic.$config.get('broadcasting.pusher.cluster'),
        wsHost: Statamic.$config.get('broadcasting.pusher.host'),
        wsPort: Statamic.$config.get('broadcasting.pusher.port'),
        wssPort: Statamic.$config.get('broadcasting.pusher.port'),
        forceTLS: false,
        encrypted: true,
        disableStats: true,
        enabledTransports: ["ws", "wss"],
    }));

});

@jasonvarga
Copy link
Member

jasonvarga commented Feb 6, 2024

I made some tweaks:

  • The config gets passed into the callback instead of the Echo object.
  • Multiple config callbacks can be used. Maybe multiple addons would want to modify the config.

We should document that you should modify the config rather than defining a completely new one.

Statamic.$echo.config(config => Object.assign(config, {
    some: 'new variable',
    key: config.key + ' but modified',
}));

Although if you know you don't have any addons etc that would also be modifying it, you can still go ahead and just override the whole thing.

Statamic.$echo.config(() => ({
  your: 'new',
  config: 'here',
})

@jasonvarga jasonvarga merged commit 2132729 into statamic:4.x Feb 6, 2024
18 checks passed
@jacksleight jacksleight deleted the feature/echo-config branch February 6, 2024 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants