Laravel-websockets: Laravel Echo will still connect to Pusher as fallback

Created on 5 Dec 2018  路  2Comments  路  Source: beyondcode/laravel-websockets

When connection fails, it will still try and connect to Pusher (over XHR) as a fallback.

More specifically to http://sockjs.pusher.com/pusher/app/.... Did I forget to change something in my config/echo/etc. files or is this expected behavior for now?

Most helpful comment

Yeah, that's how the Pusher JS client handles this.
By default it will try to connect via WebSocket and will fallback to use polling XHR requests.
You can disable this by forcing the pusher client to only use websocket connections like this:

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    wsHost: window.location.hostname,
    wsPort: 6001,
    disableStats: true,
    enabledTransports: ['ws', 'wss'] // <-- only use ws and wss as valid transports
});

All 2 comments

Yeah, that's how the Pusher JS client handles this.
By default it will try to connect via WebSocket and will fallback to use polling XHR requests.
You can disable this by forcing the pusher client to only use websocket connections like this:

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    wsHost: window.location.hostname,
    wsPort: 6001,
    disableStats: true,
    enabledTransports: ['ws', 'wss'] // <-- only use ws and wss as valid transports
});

This would be great to add to the documentation. Thanks for the fix.

Was this page helpful?
0 / 5 - 0 ratings