Gabotronix's avatar

Can't connect to soketi pusher server

I want to connect my react native app to a laravel app I run on a DigitalOcean ubuntu machine along with soketi server but I can't connect for some reason:

My broadcasting.php file

'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'log' => true,
            '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') === 'https',
                'curl_options' => [
                    CURLOPT_SSL_VERIFYHOST => 0,
                    CURLOPT_SSL_VERIFYPEER => 0,
                ],
            ],
        ],

My .env variables (changed credentials)

PUSHER_APP_KEY="9b9a489dffdf0c38f28f43777"
PUSHER_APP_SECRET="26574dsfsfsf57220cf042bd77"
PUSHER_APP_ID="13023345464644"
PUSHER_APP_CLUSTER="eu"


# SOKETI SERVER DETAILS
PUSHER_HOST=127.0.0.1
PUSHER_PORT=6001
PUSHER_SCHEME=https

Then how I start echo on my react native app:

Pusher.logToConsole = true;
        let myIp = 'laraapp.com';
        let port = 6001;
        let options = {
            key: env.PUSHER_APP_KEY,
            wsHost: myIp,
            wsPort: port,
            wssPort: port,
            enableStats: true,
            logToConsole: true,
            encrypted: true,
            forceTLS: false,
            enabledTransports: ['ws', 'wss'],
        };

        let PusherClient = new Pusher(options.key, options);
        PusherClient.connection.bind('error', () => console.log('PusherClient::error', arguments));

        const echo = new Echo({
            broadcaster: 'pusher',
            client: PusherClient,
            ...options
        });

I setup a supervisor daemon to start soketi server (I point supervisor to SSL_CERT and SSL_KEY with soketi env variables:

[program:soketi]
process_name=%(program_name)s_%(process_num)02d
command=soketi start 
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=Gabotron
numprocs=1
redirect_stderr=true
stderr_logfile=/home/Gabotron/logs/soketi.err.log
stdout_logfile=/home/Gabotron/logs/soketi.out.log
stopwaitsecs=60
stopsignal=sigint
minfds=10240
environment=SOKETI_SSL_CERT="/etc/letsencrypt/live/laraapp.com/fullchain.pem",SOKETI_SSL_KEY="/etc/letsencrypt/live/laraapp.com/privkey.pem", PATH="/home/Gabotron/.nvm/versions/node/v14.21.3/bin:%(ENV_PATH)s",NODE_ENV="production", 

And I also setup SSL certificates with certbot that I let nginx handle, my nginx conf looks like this:

server {
    server_name laraapp.com www.laraapp.com;


        root /var/www/laraapp.com/public;
    index index.php index.html;

    access_log /var/log/laraapp.com/access.log;
    error_log /var/log/laraapp.com/error.log;


    # serve static files directly
        location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
                access_log off;
                expires max;
                log_not_found off;
        }

        # removes trailing slashes (prevents SEO duplicate content issues)
        if (!-d $request_filename)
        {
                rewrite ^/(.+)/$ / permanent;
        }

        # enforce NO www
        if ($host ~* ^www\.(.*))
        {
                set $host_without_www ;
                rewrite ^/(.*)$ $scheme://$host_without_www/ permanent;
        }

        # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
        if (!-e $request_filename)
        {
                rewrite ^/(.*)$ /index.php?/ last;
                break;
        }

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~* \.php$ {
        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
                deny all;
        }

    location /ws/ {
        proxy_pass http://127.0.0.1:6001; # Point to the Soketi port
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/laraapp.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/laraapp.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot


}

server {
    if ($host = www.laraapp.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = laraapp.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name laraapp.com www.laraapp.com;
    return 404; # managed by Certbot




}

On my frontend I receive console logs trying to connect but it says unnavailable...

Pusher :  : ["Connecting",{"transport":"wss","url":"wss://laraapp.com:6001/app/9b9a4890c38f28f43777?protocol=7&client=js&version=7.0.6&flash=false"}]
 LOG  Pusher :  : ["State changed","connecting -> unavailable"]
 LOG  Pusher :  : ["Connecting",{"transport":"ws","url":"ws://laraapp.com:6001/app/9b9a4890c38f28f43777?protocol=7&client=js&version=7.0.6&flash=false"}]
 LOG  Pusher :  : ["Connecting",{"transport":"wss","url":"wss://laraapp.com:6001/app/9b9a4890c38f28f43777?protocol=7&client=js&version=7.0.6&flash=false"}]

And when I try to broadcast an event from my laravel production server I receive a blank Pusher error message:

[2024-01-11 17:27:21] production.ERROR: Pusher error: . {"exception":"[object] (Illuminate\Broadcasting\BroadcastException(code: 0): Pusher error: . at /Users/peter/Desktop/proyectos/laraapp.com/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php:128)

CAN YOU GUYS HELP ME, i have been stuck like this for a while...

0 likes
0 replies

Please or to participate in this conversation.