# Custom WebSocket Server

If you don't want to use Pusher as your WS server which is the default one, then you can follow one of the options bellow to configure your app and get it running with your custom server

## beyondcode/laravel-websockets

To replace `Pusher` with [`beyondcode/laravel-websockets`](https://beyondco.de/docs/laravel-websockets) you have to install & configure it with your app.. then modify your app's .env file as following:

{% code title="config/chatify.php" %}

```sh

PUSHER_APP_ID=pusher_app_id                           # Any random string
PUSHER_APP_KEY=pusher_app_key                         # Any random string
PUSHER_APP_SECRET=pusher_app_secret                   # Any random string
PUSHER_HOST=127.0.0.1                                 # Server host
PUSHER_PORT=6001                                      # Server port
PUSHER_SCHEME=http                                    # For SSL use `https`, otherwise use `http`.
PUSHER_APP_CLUSTER=mt1
LARAVEL_WEBSOCKETS_PORT="${PUSHER_PORT}"              # Laravel WS port

LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=private_key_path      # Optional for using SSL.
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=certificate_path    # Optional for using SSL.
```

{% endcode %}

then also you have to modify `laravel-websockets` config file to enable client events which is required to get it working well:

{% hint style="info" %}
You can make changes on this config file as your needs for other options available.
{% endhint %}

{% code title="config/websockets.php" %}

```
...
'apps' => [
        [
            ...
            'enable_client_messages' => true,         # Set to `true`
            ...
        ],
    ],
...
```

{% endcode %}

and make sure you're running the websockets server.

\
That's all you need 🚀.

{% hint style="warning" %}
if you change the env variables or any related config, then you may need to restart your websockets server.
{% endhint %}

## Laravel Reverb

First, you need to install Laravel Reverb. You can install it via composer by running the following command:

```bash
composer require laravel/reverb

php artisan reverb:install
```

After installing the package, you need to set the following environment variables in your \`.env\` file:

<pre><code><strong>REVERB_APP_ID       = your-app-id
</strong>REVERB_APP_KEY      = your-app-key
REVERB_APP_SECRET   = your-app-secret
REVERB_HOST         = your-host
REVERB_PORT         = your-port (default: 8080)
REVERB_SCHEME       = https (default: http for non-ssl)
</code></pre>

Then, Change the Pusher environment variables to Reverb environment variables:

```
PUSHER_APP_ID       = "${REVERB_APP_ID}"
PUSHER_APP_KEY      = "${REVERB_APP_KEY}"
PUSHER_APP_SECRET   = "${REVERB_APP_SECRET}"
PUSHER_HOST         = "${REVERB_HOST}"
PUSHER_PORT         = "${REVERB_PORT}"
PUSHER_SCHEME       = "${REVERB_SCHEME}"
PUSHER_APP_CLUSTER  = "mt1" (default: mt1)
BROADCAST_DRIVER    = reverb
```

That is it 🎉! You have successfully configured Laravel Reverb with Chatify.

#### Using SSL with Laravel Reverb

If you want to use SSL in your Reverb server, you need to follow the steps below:

1. update server configuration in `config/reverb.php` file. as shown below

```php
 'servers' => [
        'reverb' => [
            'host' => env('REVERB_SERVER_HOST', '0.0.0.0'),
            'port' => env('REVERB_SERVER_PORT', 8080),
            'hostname' => env('REVERB_HOST'),
            'options' => [
                'tls' => [
                    'verify_peer' => false,
                    'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
                    'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
                ],
            ],
            'max_request_size' => env('REVERB_MAX_REQUEST_SIZE', 10_000),
            'scaling' => [
                'enabled' => env('REVERB_SCALING_ENABLED', false),
                'channel' => env('REVERB_SCALING_CHANNEL', 'reverb'),
                'server' => [
                    'url' => env('REDIS_URL'),
                    'host' => env('REDIS_HOST', '127.0.0.1'),
                    'port' => env('REDIS_PORT', '6379'),
                    'username' => env('REDIS_USERNAME'),
                    'password' => env('REDIS_PASSWORD'),
                    'database' => env('REDIS_DB', '0'),
                ],
            ],
            'pulse_ingest_interval' => env('REVERB_PULSE_INGEST_INTERVAL', 15),
            'telescope_ingest_interval' => env('REVERB_TELESCOPE_INGEST_INTERVAL', 15),
        ],

    ],

```

2. update the `REVERB_SERVER_HOST` and `REVERB_SERVER_PORT` in your `.env` file

```bash
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT  = <path-to-your-certificate-file>
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK    = <path-to-your-public-key-file>
```

Thats all for SSL configuration.

## Other WS servers

For other WS servers you can follow same as the options above and what required by the custom server you're trying to use.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chatify.munafio.com/custom-websocket-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
