soketi / soketi

Next-gen, Pusher-compatible, open-source WebSockets server. Simple, fast, and resilient. 📣
https://soketi.app/
GNU Affero General Public License v3.0
4.84k stars 268 forks source link

[REQUEST] Laravel echo now requires a "cluster" option for socketi client #997

Open sektormediaofficial opened 11 months ago

sektormediaofficial commented 11 months ago

Is your feature request related to a problem? Please describe. Yes, laravel Echo now requires a manditory 'cluster' option, is this option ignored by soketi? The option is required with Laravel 10.x and laravel echo 8.x

Describe the solution you'd like Add a documentation section for laravel echo 8.x and explain what do to with this option?

Describe alternatives you've considered I've just hard-coded the cluster option in hopes that soketi pusher will just connect and ignore the cluster alltogether

codeautopilot[bot] commented 11 months ago

Implementation plan

The user request is about adding documentation for the 'cluster' option in Laravel Echo 8.x when using Soketi. The 'cluster' option is now mandatory in Laravel Echo 8.x, and the user wants to know how to handle this option when using Soketi. The user has also asked if Soketi ignores the 'cluster' option.

To address this request, we need to update the documentation and possibly the code. The documentation should explain what the 'cluster' option is, why it is now required in Laravel Echo 8.x, and how to use it with Soketi. If Soketi ignores the 'cluster' option, this should be clearly stated.

In terms of code changes, we need to review the src/adapters/adapter.ts file to understand how the 'cluster' option is handled. If necessary, we might need to modify the code to handle the 'cluster' option correctly.

Code

docs/laravel-echo-integration.md

# Laravel Echo Integration with Soketi

## Introduction
Laravel Echo is a JavaScript library that makes it easy to handle WebSockets in Laravel applications. Soketi is a simple, fast, and resilient open-source WebSocket server written in TypeScript. It's compatible with the Pusher protocol, and can be used as a drop-in replacement for Pusher in Laravel applications.

## Integration of Laravel Echo with Soketi
To integrate Laravel Echo with Soketi, you need to configure Laravel Echo to use the 'pusher' broadcaster and provide the necessary Soketi server details. Here's an example:

```javascript
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'your-pusher-key',
    wsHost: window.location.hostname,
    wsPort: 6001,
    forceTLS: false,
    disableStats: true,
});

Laravel Echo 8.x and the 'cluster' option

In Laravel Echo 8.x, a new 'cluster' option is required. This option is used to specify the cluster that your application is connected to.

If you are using Soketi with Laravel Echo, you can specify the 'cluster' option in your configuration as follows:

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'your-pusher-key',
    cluster: 'your-cluster',
    wsHost: window.location.hostname,
    wsPort: 6001,
    forceTLS: false,
    disableStats: true,
});

Please note that Soketi currently ignores the 'cluster' option and will connect to the specified 'wsHost' and 'wsPort' regardless of the 'cluster' value. This behavior may change in future versions of Soketi.


## src/adapters/adapter.ts
```typescript
// No code changes are required in this file if Soketi is supposed to ignore the 'cluster' option. 
// If changes are required, they should be implemented here and thoroughly tested.

README.md

## Using the 'cluster' option with Laravel Echo and Soketi

In Laravel Echo 8.x, a new 'cluster' option is required. This option is used to specify the cluster that your application is connected to. 

If you are using Soketi with Laravel Echo, you can specify the 'cluster' option in your configuration as follows:

```javascript
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'your-pusher-key',
    cluster: 'your-cluster',
    wsHost: window.location.hostname,
    wsPort: 6001,
    forceTLS: false,
    disableStats: true,
});

Please note that Soketi currently ignores the 'cluster' option and will connect to the specified 'wsHost' and 'wsPort' regardless of the 'cluster' value. This behavior may change in future versions of Soketi.


<details>
  <summary>Changes on docs/laravel-echo-integration.md</summary>

  # Plan
Since this is a new file, we will start by creating a structure for the documentation. The structure will include an introduction, a section on how to integrate Laravel Echo with Soketi, and a new section specifically for Laravel Echo 8.x and the 'cluster' option.

1. **Introduction**: Briefly explain what Laravel Echo and Soketi are and why they are used together.

2. **Integration of Laravel Echo with Soketi**: Explain the steps to integrate Laravel Echo with Soketi. This should include any necessary code snippets and configuration settings.

3. **Laravel Echo 8.x and the 'cluster' option**: In this section, explain what the 'cluster' option is and why it is now required in Laravel Echo 8.x. Provide instructions on how to use this option with Soketi. If Soketi ignores the 'cluster' option, state this clearly. 

The goal is to provide clear and concise instructions that will help users understand how to use the 'cluster' option with Laravel Echo 8.x and Soketi.

</details>

<details>
  <summary>Changes on src/adapters/adapter.ts</summary>

  The file `src/adapters/adapter.ts` is responsible for initializing the adapter scaling and handling various operations related to the adapter. It supports multiple drivers including 'local', 'redis', 'nats', and 'cluster'. 

To address the user's request, we need to understand how the 'cluster' option is handled in Laravel Echo and whether it has any impact on Soketi. 

Here's a step-by-step plan:

1. Review the `Adapter` class and its methods to understand how it interacts with different drivers. Pay special attention to the 'cluster' driver and how it's used.

2. Check if the 'cluster' option from Laravel Echo is being passed to the Soketi adapter. If it's not, we might need to modify the `addSocket`, `removeSocket`, or other relevant methods to accept and handle this option.

3. If the 'cluster' option is being used, understand its purpose and how it affects the connection. If Soketi is supposed to ignore this option, ensure that it's doing so.

4. If changes are required in the adapter to handle the 'cluster' option, implement these changes. This might involve modifying existing methods or adding new ones.

5. Test the changes thoroughly to ensure that the 'cluster' option is handled correctly and doesn't break any existing functionality.

Remember, any changes should be well-documented to help users understand how to use the 'cluster' option with Laravel Echo and Soketi.

</details>

<details>
  <summary>Changes on README.md</summary>

  To address the user's request, we need to add a new section in the README.md file that explains how to handle the 'cluster' option in Laravel Echo when using Soketi. 

The new section could be titled "Using the 'cluster' option with Laravel Echo and Soketi" and should be placed in an appropriate location within the document, such as after the "Soketi" section. 

The content of the section should explain what the 'cluster' option is, why it is now required in Laravel Echo 8.x, and how to use it with Soketi. If Soketi ignores the 'cluster' option, this should be clearly stated. 

The section could be structured as follows:

```markdown
## Using the 'cluster' option with Laravel Echo and Soketi

In Laravel Echo 8.x, a new 'cluster' option is required. This option is used to specify the cluster that your application is connected to. 

If you are using Soketi with Laravel Echo, you can specify the 'cluster' option in your configuration as follows:

```javascript
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'your-pusher-key',
    cluster: 'your-cluster',
    wsHost: window.location.hostname,
    wsPort: 6001,
    forceTLS: false,
    disableStats: true,
});

Please note that Soketi currently ignores the 'cluster' option and will connect to the specified 'wsHost' and 'wsPort' regardless of the 'cluster' value. This behavior may change in future versions of Soketi.



This new section will provide the necessary information for users to understand and use the 'cluster' option with Laravel Echo and Soketi.

</details>

---
Current plan usage: 82.66%

---
<div style="background-color: #f1f1f1; padding: 20px; border-radius: 10px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);">

**Have feedback or need help?**

[Discord](https://discord.gg/r72ykfvyx7)
[Documentation](https://www.codeautopilot.com/docs)
[support@codeautopilot.com](mailto:support@codeautopilot.com)

</div>
chrispage1 commented 11 months ago

I've just upgraded Laravel Echo JS package to ^1.15.3 and it seems that I am still able to use it without the cluster property.

What errors are you getting?

Yahav commented 11 months ago

and laravel echo 8.x

Laravel Echo @Latest is currently 1.15.3 What are we missing?

Recheter220 commented 10 months ago

I've just upgraded Laravel Echo JS package to ^1.15.3 and it seems that I am still able to use it without the cluster property.

What errors are you getting?

I've encountered this same situation. It's not related to the laravel-echo package, but the pusher-js. As of v8.0.0 it's now mandatory to include the cluster when instantiating the Pusher object, which can be seen in their official release notes

shahzeb1 commented 5 months ago

Pin your pusher-js version to 7.0.3 for now. That seems to work fine.