#Can't get Laravel reverb to work

13 messages · Page 1 of 1 (latest)

livid flax
#

Hello, I'm trying to use Laravel reverb and echo on my local dev. I have tried many different configuations but none have been working. I'm going to post my current config and maybe one of you can see what I'm doing wrong.

Please note I'm using Laravel Herd to run reverb.

npm run dev


\App\Events\TestEvent::dispatch("Hello from Tinker!");

The Error

echo.js:6 WebSocket connection to 'wss://0.0.0.0:8080/app/laravel-herd?protocol=7&client=js&version=8.4.0-rc2&flash=false' failed: 
# .env
BROADCAST_CONNECTION=reverb

REVERB_APP_ID=1001
REVERB_APP_KEY=laravel-herd
REVERB_APP_SECRET=secret
REVERB_HOST="0.0.0.0"
REVERB_PORT=8080
REVERB_SCHEME=https

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
<!-- Welcome Blade -->

<script>
    Window.Echo.private(`App.Models.User.1`)
        .listen('TestEvent', (e) => {
            console.log('Received message:', e.message);
        });

    window.Echo.private('test-channel')
        .listen('.test-event', (e) => {
            console.log('Received message:', e.message);
        });
</script>
// broadcasting.php

<?php

    'connections' => [

        'reverb' => [
            'driver' => 'reverb',
            'key' => env('REVERB_APP_KEY'),
            'secret' => env('REVERB_APP_SECRET'),
            'app_id' => env('REVERB_APP_ID'),
            'options' => [
                'host' => env('REVERB_HOST'),
                'port' => env('REVERB_PORT', 443),
                'scheme' => env('REVERB_SCHEME', 'https'),
                'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
            ],
            'client_options' => [
                // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
                'verify' => env('APP_ENV') !== 'local',
            ],
        ],
// echo.js

import Echo from 'laravel-echo';

import Pusher from 'pusher-js';
window.Pusher = Pusher;

window.Echo = new Echo({
    broadcaster: 'reverb',
    key: import.meta.env.VITE_REVERB_APP_KEY,
    wsHost: import.meta.env.VITE_REVERB_HOST,
    wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
    wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
    forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
    enabledTransports: ['ws', 'wss'],
});
// channels.php

<?php

use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});
// TestEvent.php

<?php

class TestEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function broadcastOn(): array
    {
        return [
            new PrivateChannel('App.Models.User.1'),
        ];
    }

    public function broadcastAs()
    {
        return 'test-event';
    }
}
broken frost
#

If you're using Herd, you should probably use the HTTPS certificate from that. You're trying to connect to 0.0.0.0 through https/tls, which isn't going to give you a valid certificate. Not sure if connecting to that IP is even going to work to begin with (it should likely be localhost)

livid flax
#

Changed .env host to REVERB_HOST="localhost" - Stopped reverb on Herd and ran it via command line

php artisan reverb:start --host="0.0.0.0" --port=8080 --hostname="stellar-forge.test"

   INFO  Starting secure server on 0.0.0.0:8080 (stellar-forge.test).

On the front-end I get the following error:

WebSocket connection to 'wss://localhost:8080/app/laravel-herd?protocol=7&client=js&version=8.4.0-rc2&flash=false' failed:

On the backend when I try to dispatch the job, I get this error:

GuzzleHttp\Exception\RequestException: cURL error 56: OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 0 (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://stellar-forge.test:8080/apps/1001/events?auth_key=laravel-herd&auth_timestamp=1730751501&auth_version=1.0&body_md5=c45e08a461872629bfc4300d6bf862ea&auth_signature=115babb51953bd1e668b80b563946a55577f7984ed62c8e184f3f110743070ad in /Users/joshwegener/Projects/Stellar-Forge/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:276

broken frost
#

It shouldn't be localhost, but rather the test domain

#

Your frontend connects to the test domain, your backend just connects to localhost iirc

livid flax
#

Changed .env:

REVERB_APP_ID=1001
REVERB_APP_KEY=laravel-herd
REVERB_APP_SECRET=secret
REVERB_HOST="stellar-forge.test"
REVERB_PORT=8080
REVERB_SCHEME=https

Added the following to .env

REVERB_TLS_CERT="/Users/joshwegener/Library/Application Support/Herd/config/php/cacert.pem"
#REVERB_TLS_PK=
REVERB_TLS_VERIFY_PEER=false
REVERB_TLS_VERIFY_PEER_NAME=false
REVERB_TLS_ALLOW_SELF_SIGNED=true

added in Reverb.php

'options' => [
    'tls' => [
        'local_cert' => env('REVERB_TLS_CERT'),
        'local_pk' => env('REVERB_TLS_PK'),
        'verify_peer' => env('REVERB_TLS_VERIFY_PEER', true),
        'verify_peer_name' => env('REVERB_TLS_VERIFY_PEER_NAME', true),
        'allow_self_signed' => env('REVERB_TLS_ALLOW_SELF_SIGNED', false),
    ],
],

front-end

WebSocket connection to 'wss://stellar-forge.test:8080/app/laravel-herd?protocol=7&client=js&version=8.4.0-rc2&flash=false' failed: 

back-end when I dispatch test

Illuminate\Broadcasting\BroadcastException: Pusher error: cURL error 35: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to stellar-forge.test:8080 (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://stellar-forge.test:8080/apps/1001/events?auth_key=laravel-herd&auth_timestamp=1730758436&auth_version=1.0&body_md5=c45e08a461872629bfc4300d6bf862ea&auth_signature=7dc31a9c98f14058c61d710cd0929b33fadec1f7a68bf57a168d42b45f42a3cd. in /Users/joshwegener/Projects/stellar-forge/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php:164```
broken frost
#
REVERB_SERVER_HOST=0.0.0.0
REVERB_SERVER_PORT=8080
 
REVERB_HOST=app.test
REVERB_PORT=443

Those should be the credentials iirc. And no need to give the cert, it'll check for herd certificates

livid flax
#

Changed to match your .env changes, removed the tls options - still erroring... I have been working on this for so long. This should be easier than this lol. I wonder what I'm doing wrong!

#

Thinking about starting a blank project and starting from scratch...

livid flax
#

I got it connected to reverb! Woot! Now I'm having a new issue... lol

<script>
    Window.Echo.private(`App.Models.User.1`).listen('test-event', (e) => {
        console.log('Received message:', e.message);
    });
</script>
Uncaught TypeError: Cannot read properties of undefined (reading 'private')
void trail
#

Try window lowercase

broken frost
#

Echo is undefined, which likely means you're running this script before the instance is set on the window