soketi icon indicating copy to clipboard operation
soketi copied to clipboard

Soketi with Laravel in different domains

Open felipesmendes opened this issue 2 years ago • 22 comments

Soketi with Laravel Hello Guys,

I'm trying to use real-time notifications using Soketi

So I createg the Soketi server in one separeted server with nodejs on port 6001 and SSL using letsencrypt.

Then I Created the notification

Added the JS script to layout:

 Echo.private('App.User.' + {{Auth::id()}})
        .notification((data) => {
         console.log(data);
        });

Added the this code compiled in layout too:

import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    wsHost: process.env.MIX_PUSHER_HOST,
    wsPort: process.env.MIX_PUSHER_PORT,
    wssPort: process.env.MIX_PUSHER_PORT,
    forceTLS: false,
    encrypted: true,
    disableStats: true,
    enabledTransports: ['ws', 'wss'],
});

So when I was in development ambient the notifications cakes properly, sended by one server without SSL (http://sede.inoprime.com.br), but when I was on production server It not work and this server has SSL and its diferent from Soketi server. Application Laravel (https://trackerprime.inoprime.com.br) Soketi Server (https://servicos.inoprime.com.br)

I found this two diferences when the aplications calls the websocket link: wss://servicos.inoprime.com.br:6001/app/app-key?protocol=7&client=js&version=7.0.6&flash=false

In development the response is:

{event: "pusher_internal:subscription_succeeded", channel: "private-App.User.1"}

In Production I got:

{ "event": "pusher:connection_established", "data": "{"socket_id":"8565042074.5045547206","activity_timeout":30}" } Anyone have any idea what they might be getting?

felipesmendes avatar Mar 14 '22 13:03 felipesmendes

Seems like it could be a config issue. Are you sure the App Key is correct?

The server is responding to requests but not to wss requests.

alexhackney avatar Mar 17 '22 15:03 alexhackney

Where do I configure the app key in soketi? I used the default configuration.

felipesmendes avatar Mar 17 '22 15:03 felipesmendes

You have to create a config.

https://docs.soketi.app/getting-started/environment-variables

On Thu, Mar 17, 2022 at 11:41 AM felipesmendes @.***> wrote:

Where do I configure the app key in soketi? I used the default configuration.

— Reply to this email directly, view it on GitHub https://github.com/soketi/soketi/issues/418#issuecomment-1070992523, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEAC2WH7FADKLC74QSAK63VANHCVANCNFSM5QVQ3F4Q . You are receiving this because you commented.Message ID: @.***>

alexhackney avatar Mar 17 '22 15:03 alexhackney

Hello @alexhackney I created the config and change the app key but I already with this problem, I think its some problem in Laravel Echo client, is there any way to turn on the debug on it?

felipesmendes avatar Mar 17 '22 16:03 felipesmendes

The timeout is what makes me think its a server issue. You should be able to connect to the server even with the wrong key.

In Laravel echo is obviously a js client, so you can do the same things there you can do with any js console.logging is helpful and chrome webtools is super helpful as well. Your making it available to window so you can access it from the console window as well.

I find this tool is super helpful: You can test with this tool: https://www.piesocket.com/websocket-tester

I would verify your .env is the same in both env's as well.

alexhackney avatar Mar 17 '22 16:03 alexhackney

I already using this chrome extension See the connection working: image

The .env is same in both of servers (develop and production)

The unique thing that is diferent is the origin of requisition:

Development:

Accept-Encoding: gzip, deflate, br
Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: no-cache
Connection: Upgrade
Host: socket.inoprime.com.br:6002
Origin: http://localhost:8000
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: 2qKJFymINL4suwoMXf7ieA==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36

image

Production:

Accept-Encoding: gzip, deflate, br
Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: no-cache
Connection: Upgrade
Host: socket.inoprime.com.br:6002
Origin: https://trackerprime.inoprime.com.br
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: KeO/uAPqgRC0SCWdoX7Mkw==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36

image

felipesmendes avatar Mar 17 '22 16:03 felipesmendes

It's clearly not the same server.

You said you were connecting to: Soketi Server (https://servicos.inoprime.com.br/) in your original post

but here you're connecting to socket.inoprime.com.br:6002

Different server, different port.

I can connect to the second server with the tool from here so it's not a server issue. It's a config issue.

Make sure your prod env has MIX_PUSHER_APP_KEY, MIX_PUSHER_HOST, MIX_PUSHER_PORT, MIX_PUSHER_PORT,

And they are set properly.

alexhackney avatar Mar 17 '22 17:03 alexhackney

Also, locally you're not using an SSL and in production you are.

Your server is probably setup for only wss.

So you could try removing the ws entries and force tls.

Your screenshots dont really help, I'd need to see the wss server its trying to connect to on both envs to verify.

alexhackney avatar Mar 17 '22 17:03 alexhackney

@alexhackney Yes its beause I changed to this configuration thinking thats the problem in port or ssl

https://docs.soketi.app/getting-started/backend-configuration/nginx-configuration

and the prod end has this configuration like the official documentation

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_HOST="${PUSHER_HOST}"
MIX_PUSHER_PORT="${PUSHER_PORT}"

felipesmendes avatar Mar 17 '22 17:03 felipesmendes

But are the values the same?

All MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" does is make MIX_PUSHER_APP_KEY = PUSHER_APP_KEY and makes it available in mix.

Is PUSHER_APP_KEY the same in both envs? along with the other env vars?

alexhackney avatar Mar 17 '22 17:03 alexhackney

Also, locally you're not using an SSL and in production you are.

Your server is probably setup for only wss.

So you could try removing the ws entries and force tls.

Your screenshots dont really help, I'd need to see the wss server its trying to connect to on both envs to verify.

For sure, but where in the configuration of the server I setup for ws and wss?

felipesmendes avatar Mar 17 '22 17:03 felipesmendes

Your server is functioning.

This would be in echo config.

alexhackney avatar Mar 17 '22 17:03 alexhackney

But are the values the same?

All MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" does is make MIX_PUSHER_APP_KEY = PUSHER_APP_KEY and makes it available in mix.

Is PUSHER_APP_KEY the same in both envs? along with the other env vars?

Yes, in both of it are the same.

felipesmendes avatar Mar 17 '22 17:03 felipesmendes

Your server is functioning.

This would be in echo config.

The Echo config is this:

window.Echo = new laravel_echo__WEBPACK_IMPORTED_MODULE_0__["default"]({
  broadcaster: 'pusher',
  key: "tracker",
  wsHost: "socket.inoprime.com.br",
  wsPort: "6002",
  wssPort: "6002",
  forceTLS: false,
  encrypted: true,
  disableStats: true,
  enableLogging:true,
  enabledTransports: ['ws', 'wss']
});

felipesmendes avatar Mar 17 '22 17:03 felipesmendes

Right so remove ws and set forcetls to true

alexhackney avatar Mar 17 '22 17:03 alexhackney

Right so remove ws and set forcetls to true

I changed to this configuration:

window.Echo = new laravel_echo__WEBPACK_IMPORTED_MODULE_0__["default"]({
  broadcaster: 'pusher',
  key: "tracker",
  wsHost: "socket.inoprime.com.br",
  wsPort: "6002",
  wssPort: "6002",
  forceTLS: true,
  encrypted: true,
  disableStats: true,
  enableLogging:true,
  enabledTransports: ['wss']
});

and then the application did connected to soketi server: image

felipesmendes avatar Mar 17 '22 17:03 felipesmendes

So youre good?

alexhackney avatar Mar 17 '22 18:03 alexhackney

Sorry, I spelled it wrong, the application did not connect to the Soketi server.

On Thu, Mar 17, 2022 at 3:47 PM Alex Hackney @.***> wrote:

So youre good?

— Reply to this email directly, view it on GitHub https://github.com/soketi/soketi/issues/418#issuecomment-1071207175, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHSNRPOGLNCKZ3EABYFGVLVAN45FANCNFSM5QVQ3F4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

felipesmendes avatar Mar 17 '22 19:03 felipesmendes

Try changing enabledTransports: ['wss'] to enabledTransports: ['ws', 'wss']

elbojoloco avatar Mar 18 '22 10:03 elbojoloco

Try changing enabledTransports: ['wss'] to enabledTransports: ['ws', 'wss']

Hello @elbojoloco, before the enabledTransports it was like you told, with ws and wss configuration then in development server the Laravel Echo subscribed to private channel as espected. (See the image) image

But in production the Laravel Echo client just connect to Soketi server and don't subscribe to a private channel as developement server did. Check the image. image

felipesmendes avatar Mar 18 '22 11:03 felipesmendes

It's a private channel, and your screenshot does not include XHR, so I can't see if your channel auth call is successful, but that would be my first bet of where your problem lies.

elbojoloco avatar Mar 18 '22 19:03 elbojoloco

Sorry @elbojoloco, here is the XHR request of auth working properly

image image

felipesmendes avatar Mar 21 '22 20:03 felipesmendes