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 you have to install & configure it with your app.. then modify your app's .env file as following:

config/chatify.php

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.

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

You can make changes on this config file as your needs for other options available.

config/websockets.php
...
'apps' => [
        [
            ...
            'enable_client_messages' => true,         # Set to `true`
            ...
        ],
    ],
...

and make sure you're running the websockets server.

That's all you need 🚀.

if you change the env variables or any related config, then you may need to restart your websockets server.

Laravel Reverb

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

composer require laravel/reverb

php artisan reverb:install

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

REVERB_APP_ID       = your-app-id
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)

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

 '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),
        ],

    ],
  1. update the REVERB_SERVER_HOST and REVERB_SERVER_PORT in your .env file

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.

Last updated