Reputation: 3189
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:
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?
Upvotes: 3
Views: 2091
Reputation: 3189
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
.
Upvotes: 1