laravel-websockets icon indicating copy to clipboard operation
laravel-websockets copied to clipboard

failed: WebSocket is closed before the connection is established.

Open simplethemes opened this issue 7 years ago • 23 comments

First of all. thanks for building this package!

For some reason, I get this message in the console whenever I terminate and re-run websockets:serve.

failed: WebSocket is closed before the connection is established.

The only way I've found to successfully get back up and running is to change PUSHER_APP_KEY in config and bootstrap.js and npm run dev.

I'm worried this will have problems in production. Am I missing something or is there a better way to terminate and restart the websocket server?

(Laravel 5.7 on Homestead)

simplethemes avatar Jan 10 '19 23:01 simplethemes

I'm seeing the same error message in the browser. I've been unable to reliably connect, it's very intermittent.

In the artisan terminal I can see that it connects for a split second and then immediately disconnects:

New connection opened for app key app.
Connection id 576957883.192427708 sending message {"event":"pusher:connection_established","data":"{\"socket_id\":\"576957883.192427708\",\"activity_timeout\":30}"}
Connection id 576957883.192427708 closed.

Composer: laravel/framework: 5.7.19 beyondcode/laravel-websockets: 1.0.4 pusher/pusher-php-server: 3.3.0

NPM: laravel-echo: 1.5.2 pusher-js: 4.3.1

adam1010 avatar Jan 11 '19 12:01 adam1010

I was able to circumvent this error by specifying enabledTransports in my JS config:

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    wsHost: window.location.hostname,
    wsPort: 6001,
    disableStats: true,
    enabledTransports: ['ws', 'wss'] // <- added this param
});

Otherwise the pusher-js api tries to connect to the official Pusher service.

simplethemes avatar Jan 11 '19 19:01 simplethemes

I'm still seeing this issue (in production only, not locally)

Composer: laravel/framework: 5.8.3 beyondcode/laravel-websockets: 1.1.1 pusher/pusher-php-server: 3.3.1

NPM: laravel-echo: 1.5.3 pusher-js: 4.4.0

avrahamappel avatar Mar 08 '19 18:03 avrahamappel

@simplethemes That worked for me.

lukepolo avatar Mar 22 '19 14:03 lukepolo

I am also facing the same issue is there any solution found?

marslankhalid avatar Sep 19 '19 11:09 marslankhalid

Me too. Did anyone found a solution for this problem?

94praneeth avatar Nov 22 '19 06:11 94praneeth

I had faced same issue.

In my case I found out it only occurred on Windows Edge browser.

When I switched to Chrome or Opera the issue disappeared.

tumainimosha avatar Dec 05 '19 11:12 tumainimosha

I am only facing this error on production host.

mrbarnk avatar Dec 09 '19 13:12 mrbarnk

clear the cookies, specifically PusherTransportNonTLS

jmattheson avatar Jan 07 '20 10:01 jmattheson

do you think that this issue can be related to cluster? Because I am getting the same error. I have checked all documentation still didn't find anything. it was working good before on server but once I reuploaded my files the error started to happing do you think this issue is related to port or cluster??

ponikar avatar Jan 10 '20 19:01 ponikar

@simplethemes solution worked

enabledTransports: ["ws", "wss"],

lukepolo avatar Jan 10 '20 19:01 lukepolo

it is not working for me! I have added this line still getting error wss://secretscrush.com:6001/app/keyisnotitswhatyouthink?protocol=7&client=js&version=4.4.0&flash=false' Websockets is closed before established

ponikar avatar Jan 11 '20 06:01 ponikar

hello! guys. php artisan optimize:clear and sudo php artisan websockets:serve worked for me. try it

ZeusGolohor avatar Feb 29 '20 01:02 ZeusGolohor

PusherTransportNonTLS

For some reason it isn't working in my Brave Browser, but it's working in my Chrome Brower. Then i did a quick search about "Websockets not working in Brave Brower" then saw this - https://community.brave.com/t/browser-is-having-issues-with-wss-websocket-secure/70209/7

jimdeveloper89 avatar May 15 '20 03:05 jimdeveloper89

I fixed this issue by using an older version of pusher-js. 4.3.1 is the one used in the demo/dashboard so I switched to that

BKorenek avatar Jul 12 '20 18:07 BKorenek

Downgrading to npm install [email protected] still works in October 2020

xlcrr avatar Oct 04 '20 15:10 xlcrr

Check your port that it is not disabled. ufw allow 6001 - open this port

igortsapiro avatar Oct 06 '20 10:10 igortsapiro

Check your port that it is not disabled. ufw allow 6001 - open this port

Worked for me!!!! Thank you very much.

maikeru-desu avatar Nov 19 '20 19:11 maikeru-desu

Also when following the blogpost from Alex Bouma (referenced in the official docs) for setting laravel-websockets up with forge make sure you define the env variable LARAVEL_WEBSOCKETS_PORT

It defaults to 6001 but in the blogpost Alex uses 6002. So on production the env variable would be 6002.

jandante avatar Dec 27 '20 21:12 jandante

Hello there, I want to know how can we use laravel-websockets with React Native. How do I config my project? Do I need to install pusher-js on the client-side?

ponikar avatar Dec 28 '20 13:12 ponikar