Laravel Echo
Laravel Echo is compatible with the PusherJS library. Therefore, its configuration resembles the typical configuration of a PusherJS client such as the example configuration in the previous section of documentation:
1
import Echo from 'laravel-echo';
2
​
3
window.Pusher = require('pusher-js');
4
​
5
let laravelEcho = new Echo({
6
broadcaster: 'pusher',
7
key: process.env.MIX_PUSHER_APP_KEY,
8
wsHost: process.env.MIX_PUSHER_HOST,
9
wsPort: process.env.MIX_PUSHER_PORT,
10
wssPort: process.env.MIX_PUSHER_PORT,
11
forceTLS: false,
12
encrypted: true,
13
disableStats: true,
14
enabledTransports: ['ws', 'wss'],
15
});
16
​
17
laravelEcho.private(`orders.${orderId}`)
18
.listen('OrderShipmentStatusUpdated', (e) => {
19
console.log(e.order);
20
});
Copied!
Make sure that enabledTransports is set to ['ws', 'wss']. If not set, in case of connection failure, the client will try other transports such as XHR polling, which soketi doesn't support.
The MIX_* environment variables are typically declared in your Laravel application's .env file:
1
PUSHER_APP_KEY=app-key
2
PUSHER_APP_ID=app-id
3
PUSHER_APP_SECRET=app-secret
4
PUSHER_HOST=127.0.0.1
5
PUSHER_PORT=6001
6
​
7
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
8
MIX_PUSHER_HOST="${PUSHER_HOST}"
9
MIX_PUSHER_PORT="${PUSHER_PORT}"
Copied!
For SSL configuration, see the Pusher SDK example for SSL.
Copy link