skip to Main Content

I’ve been trying to set up my a broadcast system with pusher and followed the documentation step by step. when i start the server i get an error

"Uncaught Options object must provide a cluster"

on my console.


'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'host' => env('PUSHER_HOST', 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
                'port' => env('PUSHER_PORT', 443),
                'scheme' => env('PUSHER_SCHEME', 'https'),
                'encrypted' => true,
                'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
              
            ],
            'client_options' => [
                // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
            ],
        ],


so I checked my options object in the broadcast config and i noticed my config doesn’t have a cluster option so i added it manually, but still have that error.

.env

PUSHER_APP_ID=1529400
PUSHER_APP_KEY=521a8d3a78ab50e2c14d
PUSHER_APP_SECRET=ce93e12b5f74f8280624
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1
e here

broadcast.php



'connections' => [

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'host' => env('PUSHER_HOST', 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
                'port' => env('PUSHER_PORT', 443),
                'scheme' => env('PUSHER_SCHEME', 'https'),
                'encrypted' => true,
                'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
                'cluster' => env('PUSHER_APP_CLUSTER'),
            ],
            'client_options' => [
                // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
            ],
        ],


3

Answers


  1. Joshua,

    I ran into the same issue.

    The pusher folks now make it mandatory: https://github.com/pusher/pusher-js/releases

    I’m rolling my code back to previous version of pusher, hoping that works.

    Login or Signup to reply.
  2. I encountered the same error and solved it by adding cluster to the parameters that are passed in the new Echo instance:
    bootstrap.js:

    added cluster:import.meta.env.VITE_PUSHER_APP_CLUSTER,

    
    
    import Echo from 'laravel-echo';
    
    import Pusher from 'pusher-js';
    window.Pusher = Pusher;
    window.Echo = new Echo({
        broadcaster: 'pusher',
        key: import.meta.env.VITE_PUSHER_APP_KEY,
        wsHost: import.meta.env.VITE_PUSHER_HOST ?? `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`,
        wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80,
        wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443,
        forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https',
        enabledTransports: ['ws', 'wss'],
        disableStats: true,
        cluster:import.meta.env.VITE_PUSHER_APP_CLUSTER,//added this line
    });
    

    Also, make sure that it is added in the broadcasting.php in options array:

     'connections' => [
    
            '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'),
                    'encrypted' => true,
                    'host' => '127.0.0.1',
                    'port' => 6001,
                    'scheme' => 'http'
                ],
                'client_options' => [
                    // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
                ],
            ],
    ...
    

    EDIT
    I realized that with version 8.0.0, the cluster option is mandatory. Another problem is that if you are using the Laravel-WebSockets package as a drop-in replacement for the pusher, it would be a problem because, in production, pusher connects to that cluster you provided in the options instead. So what I did is that I uninstalled pusher-js version 8.0.0 and installed pusher version 7.6 which does not require a cluster: npm i [email protected]

    Login or Signup to reply.
  3. do this at bootstrap.js, works great to me:

    window.Echo = new Echo({
    broadcaster: 'pusher',
    key: import.meta.env.VITE_ABLY_PUBLIC_KEY,
    wsHost: 'realtime-pusher.ably.io',
    wsPort: 443,
    disableStats: true,
    encrypted: true,
    cluster: 'eu',
    

    });

    you can choose cluster location here:
    https://pusher.com/docs/channels/miscellaneous/clusters/
    at the it it doesnt matter what you put there. I am using ably.com for sockets

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search