4

I am trying to setup websockets on larvel-9.0 project. when I try to open /laravel-websockets I am getting the following error in console. project is setup on Ubuntu 20.04.4.

pusher.min.js:8 WebSocket connection to 'wss://dev.mydomain.in:6001/app/mywebsocketkey?protocol=7&client=js&version=4.3.1&flash=false' failed:

I am getting an success response when I am trying to connect this through postman with url

wss://dev.mydomain.in:6001/app/mywebsocketkey?protocol=7&client=js&version=4.3.1&flash=false

and i am getting following response in postman.

{
    "event": "pusher:connection_established",
    "data": "{\"socket_id\":\"371175048.259495464\",\"activity_timeout\":30}"
}

I have followed Websockets documentation.

Here are the broadcast.php configuration

'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,
                'encrypted' => true,
                'host' => 'dev.mydomain.in',
                'port' => 6001,
                'scheme' => 'https',
                'curl_options' => [
                    CURLOPT_SSL_VERIFYHOST => 0,
                    CURLOPT_SSL_VERIFYPEER => 0,
                ]
            ],
            'client_options' => [
                // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
            ],
        ],

Websockets.php

'apps' => [
        [
            'host' => env('LARAVEL_WEBSOCKETS_HOST', "127.0.0.1"),
            'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
            'id' => env('PUSHER_APP_ID'),
            'name' => env('APP_NAME'),
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'path' => env('PUSHER_APP_PATH'),
            'capacity' => null,
            'enable_client_messages' => true,
            'enable_statistics' => true,
            'encrypted' => true
        ],
    ],

bootstrap.js

import Echo from "laravel-echo"

window.Pusher = require('pusher-js');

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

.env

PUSHER_APP_ID=1234
PUSHER_APP_KEY=mywebsocketkey
PUSHER_APP_SECRET=hjhasjdhajsh
PUSHER_APP_CLUSTER=mt1
LARAVEL_WEBSOCKETS_HOST="dev.mydomain.in"
LARAVEL_WEBSOCKETS_PORT=6001
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/usr/dev/ssl-fullchain.pem"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/usr/dev/ssl.key"
LARAVEL_WEBSOCKETS_SSL_PASSPHRASE=null
asimdev
  • 705
  • 1
  • 8
  • 22

1 Answers1

0

Try to put the same value for PUSHER_APP_ID, PUSHER_APP_KEY and PUSHER_APP_SECRET in .env file

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33459775) – Insane Skull Dec 24 '22 at 09:04