question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

laravel Broadcasting in private channels is not working.( cant subscribe to private channels automaticaly)

See original GitHub issue
  • Echo Version: 1.10.0
  • Laravel Version: 8.4.0
  • PHP Version: 7.4
  • NPM Version: 6.14.6
  • Node Version: 4.1.0
  • pusher/pusher-php-server: 4.1.5
  • pusher-js: 7.0.3

Description:

I use pusher and laravel-echo to create chat app in laravel. public Channels work properly.

I use pusher.com debug console and I realized in PrivateChannel laravel-echo can’t subscribe users to Available private channels automaticaly. notice that commented codes is for public channel.

App\Events\ChatBroad.php is:

    public function broadcastOn()
    {
        //        return new channel('recieve-chat.' . $this->chat['reciever_id']);
        return new PrivateChannel('recieve-chat.' . $this->chat['reciever_id']);
    }

routes/channels.php is:

Broadcast::channel('recieve-chat.{reciever_id}', function ($user , $reciever_id) {
      return true;
   // return $user->id == $reciever_id;

});

and in App\Providers\BroadcastServiceProvider i use this middleware:

Broadcast::routes(['middleware' => ['auth']]);

bootstrap.js is:

import Echo from 'laravel-echo'

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

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '83b97539662b786ffabb',
    cluster: 'eu',
    forceTLS: true,
    authEndpoint: '/broadcasting/auth',
    csrfToken: $('meta[name="csrf-token"]').attr('content'),
});

blade view file:

        <script src="{{asset('js/app.js')}}"></script>
        <script>
            {{--window.addEventListener('DOMContentLoaded' , function () {--}}
            {{--    Echo.channel('recieve-chat.{{Auth::id()}}' )--}}
            {{--        .listen('ChatBroad', (e) => {--}}
            {{--            window.livewire.emit('recieve:' + e.chat.bid_id , e.chat);--}}
            {{--            $(chatScrollDown('.chat'+ e.chat.bid_id ));--}}
            {{--        });--}}
            {{--});--}}

        window.addEventListener('DOMContentLoaded' , function () {
            Echo.private('recieve-chat.{{Auth::id()}}' )
                .listen('ChatBroad', (e) => {
                    window.livewire.emit('recieve:' + e.chat.bid_id , e.chat);
                    $(chatScrollDown('.chat'+ e.chat.bid_id ));
                });
        });
    </script>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
pilditcommented, Jan 18, 2022

Hey can you please re-share that repo ? I have the same issue

4reactions
driesvintscommented, Mar 15, 2021

Okay I got it working. A couple of things:

Hope that helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel Broadcast Private Channel doesnt work - Stack Overflow
and my private channel now subscribed at events, but now i got an error on console app.js:21789 POST 127.0.0.1:8000/broadcasting/auth 403 ( ...
Read more >
Laravel Pusher Doesn't Join Private Channel - Laracasts
Hey, there. So I'm using Laravel 5.8, and I have this problem in which my Laravel Echo code doesn't trigger Pusher to join...
Read more >
Broadcasting - Laravel - The PHP Framework For Web Artisans
Private channels require you to authorize that the currently authenticated user can actually listen on the channel. This is accomplished by making an...
Read more >
What is a channel? | Slack
private channels. In Slack, channels can be public or private. Public channels promote transparency and inclusivity. Any member of your workspace (but not...
Read more >
Event Broadcasting - Laravel guide
Private channels require you to authorize that the currently authenticated user can actually listen on the channel. This is accomplished by making an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found