Harinath R
Harinath R

Reputation: 163

Laravel-Websocket closed before connection is established

I am developing a laravel application in which real-time data is to be extracted using laravel-WebSockets package.I have seen people having issues at production side but this is on development side. I am accessing web-app using host-entry

All initial steps completed( downloading laravel-WebSocket package, pusher-js, php-pusher-server)

And executed php artisan websockets:serve. When I refreshed browser I am getting error in console app.js:40145 WebSocket connection to 'wss://erweb.in.linuxense.com:6001/app/erkey?protocol=7&client=js&version=6.0.3&flash=false' failed: WebSocket is closed before the connection is established. app.js:42637 WebSocket connection to 'wss://erweb.in.linuxense.com:6001/app/erkey?protocol=7&client=js&version=6.0.3&flash=false' failed: WebSocket opening handshake timed out

Things checked

  1. Port 6001 is open & listening. Verified using netstat -tulpn

  2. Echo config - window.Echo = new Echo({ broadcaster: 'pusher', key: process.env.MIX_PUSHER_APP_KEY, forceTLS: true, wsHost: window.location.hostname, encrypted: false, wsPort: 6001, wssPort: 6001, disableStats: true, enabledTransports: ['ws', 'wss'] });

  3. In 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'), 'useTLS' => true, 'host' => '127.0.0.1', 'port' => 6001, 'scheme' => 'http', 'encrypted' => false, ], ],

` 4. No changes made to SSL part of websocket config file

Upvotes: 2

Views: 6575

Answers (2)

Naveed Ali
Naveed Ali

Reputation: 369

I was getting the same error but when I changed the pusher version to "pusher-js": "^4.3.1" in package.json the issue was resolved

Upvotes: 1

Harinath R
Harinath R

Reputation: 163

Yes, I got it to work. The first and foremost thing is to downgrade your pusher from 6.* to 4.*.

There is some issue with that. Here is the config inside

resources/js/bootstrap.js
 window.Echo = new Echo({ broadcaster: 'pusher', key: 
 process.env.MIX_PUSHER_APP_KEY, 
 wsHost: window.location.hostname, 
 wsPort: 6002, 
 wssPort: 6002, 
 disableStats: true, 
 enabledTransports: ['ws', 'wss'],
 });

Whenever you make a change with the bootstrap.js file, make sure to `

run npm run dev/npm run production`.

Also add verify_peer=>false in ssl array inside config/websockets.php

Upvotes: 2

Related Questions