websocketlaravel-10laravel-websockets

Connection timeout Laravel 10 and soketi


I'm using docker for soketi, when an event is dispatched, I can see logs in soketi docker logs, but I have connection timeout issue on the browser with Laravel Echo. Here's my current setup:

# docker-compose.yml

  soketi:
    image: 'quay.io/soketi/soketi:latest-16-alpine'
    environment:
      SOKETI_DEBUG: "${SOKETI_DEBUG-1}"
      SOKETI_METRICS_SERVER_PORT: "9601"
      SOKETI_METRICS_ENABLED: "${SOKETI_METRICS_ENABLED-1}"
    ports:
      - "6001:6001"
      - "9601:9601"
# .env
BROADCAST_DRIVER=pusher
PUSHER_HOST=host.docker.internal
PUSHER_PORT=6001
PUSHER_APP_ID=app-id
PUSHER_APP_KEY=app-key
PUSHER_APP_SECRET=app-secret
PUSHER_SCHEME=http
SOKETI_DEBUG=1
#broadcasting.php
        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'host' => env('PUSHER_HOST', '127.0.0.1'),
                'port' => env('PUSHER_PORT', 6001),
                'scheme' => env('PUSHER_SCHEME', 'http'),
                'encrypted' => true,
                'useTLS' => env('PUSHER_SCHEME', 'http') === 'https',
            ],
        ],

I can see ok returned by 127.0.0.1:6001

const echo = new Echo({
  broadcaster: 'pusher',
  key: 'app-key',
  wsHost: '127.0.0.1',
  wsPort: 6001,
  wssPort: 6001,
  forceTLS: false,
  encrypted: true,
  disableStats: true,
  enabledTransports: ['ws', 'wss'],
});

const channel = echo.channel('my-channel');

channel.listen('.user.login', (e: unknown) => {
  console.log('🚀 ~ file: index.vue:29 ~ channel.listen ~ e:', e);
});

and I got

index.vue:26 WebSocket connection to 'wss://127.0.0.1:6001/app/app-key?protocol=7&client=js&version=7.6.0&flash=false' failed: WebSocket is closed before the connection is established`

I'm using "laravel-echo": "1.15.2", and "pusher-js": "7.6.0",. I had to downgrade pusher latest to 7.6 as 8.0 they added cluster as a mandatory option.

Any idea? Thanks in advance

downgrade laravel echo and pusher to different versions as well as soketi, but no luck


Solution

  • so I solved the issue, it's because I'm using a reverse proxy (https), it forces the connection to be wss instead of ws. Hence, I put soketi server behind the reverse proxy and set forceTLS to true, it works as expected.