1

I am working on a realtime chatting application and I am using websocket with laravel

I am using library beyoundcode/laravel-websocket

I have change broadcast driver to pusher and have configured broadcaster.php to this

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

When I run an event using

event(new App\Events\UserStatusEvent())  

Instead of sending message to localhost which is 127.0.0.1 stated in pusher option it sends to pusher.com

I clear clear my cache and config not changes

class UserStatusEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function __construct()
    {
        //
    }

    public function broadcastOn()
    {
        return new PresenceChannel('status-update');
    }
}

.env

BROADCAST_DRIVER=pusher
CACHE_DRIVER=array
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

PUSHER_APP_ID=skldfjiklkd
PUSHER_APP_KEY=sdlkfewif
PUSHER_APP_SECRET=slkdfifwef
PUSHER_APP_CLUSTER=mt1

bootstrap.js

import axios from 'axios';
window.axios = axios;

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';


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,
    cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER ?? 'mt1',
    wsHost: import.meta.env.VITE_PUSHER_HOST ? 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'],
});
13
  • Can you please update your question and include the following values from your .env file ? QUEUE_CONNECTION, BROADCAST_DRIVER, and all other keys that start with PUSHER_* ? Also please include the resources/js/bootstrap.js file in your question. P.S. laravel-websockets by BeyondCode is no longer maintained, it's highly recommended that you refrain from using it. Instead, wait for a few days because Laravel Reverb is about to be released, so it's a better option for the current time. Commented Mar 7, 2024 at 12:16
  • @EyadBereh I have updated my question. Thanks for the update on Laravel Reverb. Can you notify me when it is launched Commented Mar 7, 2024 at 12:28
  • The .env file looks legit, but is that your full bootstrap.js file? I think it's missing more code from the pusher-js client. Regarding Laravel Reverb, Taylor Otwell said that it will be released along with Laravel 11 next Tuesday, that's 12th of March. When it gets released, I'll comment on this question to remind you. Commented Mar 7, 2024 at 12:33
  • @EyadBereh There are other code in bootstrap.js for echo but it is commented out. I want to be able to send messages to the laravel sockets first before uncommenting and using the echo code on bootstrap.js. I will be waiting for the laravel reverb update. Commented Mar 7, 2024 at 12:46
  • Yes, that's the problem. The commented code is the code that's meant to connect to your 127.0.0.1:6001 server. Are you using the pusher JS client directly instead of Laravel Echo ? Commented Mar 7, 2024 at 12:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.