3

I am using laravel-websockets package for some real-time features. I am using redis as queue connection. I have an event TestUpdated which I am broadcasting on test.{id} private channel. The event gets fired and caught by the client properly when I am on a local machine. But on production server, I get BroadcastException thrown:

Illuminate\Broadcasting\BroadcastException in /home/forge/mydomain.com/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php:117

Horizon dashboard also exposes the event data:

{
event: {
test: {
class: "App\Test",
id: 1,
relations: [
],
connection: "mysql"
},
socket: null
},
connection: null,
queue: null,
chainConnection: null,
chainQueue: null,
delay: null,
chained: [
]
}

Fragment of my websockets.php config file:

'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'enable_client_messages' => true,
        'enable_statistics' => false,
    ],
],

My observations:

  • Pusher gets connected. authEndpoint hits properly. I
  • Presence channel works.
  • The noticable difference between local machine and production is that on production the scheme is https

I am using an arbitrary pusher app id, key and secret (someId, someKey and someSecret'). My client-side config:

window.Echo = new Echo({
    authEndpoint: 'my/endpoint',
    broadcaster: 'pusher',
    key: 'someKey',
    wsHost: process.env.NODE_ENV == 'development' ? window.location.hostname : 'mydomain.com',
    wsPort: 6001,
    wssPort: 6001,
    disableStats: true,
    encrypted: process.env.NODE_ENV == 'development' ? false : true
});

Config from broadcasting.php:

'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'app_id' => env('PUSHER_APP_ID'),
        'options' => [
            'cluster' => env('PUSHER_APP_CLUSTER'),
            'encrypted' => true,
            'host' => '127.0.0.1',
            'port' => 6001,
            'scheme' => env('PUSHER_SCHEME')
        ],
    ],

How do I fix this?

1
  • try changing broadcasting.php file host key. Commented Apr 18, 2019 at 8:44

1 Answer 1

1

For anyone having the same issue:

I changed host to the production URL:

Here is the updated config:

'pusher' => [
    'driver' => 'pusher',
    'key' => env('PUSHER_APP_KEY'),
    'secret' => env('PUSHER_APP_SECRET'),
    'app_id' => env('PUSHER_APP_ID'),
    'options' => [
        'cluster' => env('PUSHER_APP_CLUSTER'),
        'encrypted' => true,
        'host' => env('PUSHER_HOST'),
        'port' => 6001,
        'scheme' => env('PUSHER_SCHEME')
    ],
],

And in the .env file:

PUSHER_HOST=example.com

Remember to exclude http/https from the host. It's not https://example.com, it's example.com.

Sign up to request clarification or add additional context in comments.

2 Comments

I have the same problem. I'm not very experienced with Pusher. On local it is working so fine, but on production server broadcasting not working. Tried your solution but no luck.
@Mycodingproject Have you solved the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.