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.

pusher and laravel-echo cant subscribe automaticaly to private channel

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:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
farshid-ahmadiancommented, Mar 15, 2021

in App\Providers\BroadcastServiceProvider.php

 public function boot()
    {
        Broadcast::routes();

        require base_path('routes/channels.php');
    }

we dont need any middleware!!

0reactions
farshid-ahmadiancommented, Mar 13, 2021

@ben-pusher hey there, if auth endpoint has problem. irecieve 500 error in console. i checked all of this. and i describe the problem and some additional data in here . thank you 🌺

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Pusher/Laravel echo error on subscribing to private channel ...
Pusher/Laravel echo error on subscribing to private channel: Auth value for subscription to channel is invalid: should be of format 'key: ...
Read more >
Broadcasting - Laravel - The PHP Framework For Web Artisans
When using Laravel Echo, the HTTP request to authorize subscriptions to private channels will be made automatically; however, you do need to define...
Read more >
Broadcasting | laravel - GitHub Pages
When using Laravel Echo, the HTTP request to authorize subscriptions to private channels will be made automatically; however, you do need to define...
Read more >
Event Broadcasting - Laravel guide
When using Pusher and Laravel Echo, you should specify pusher as your desired ... subscriptions to private channels will be made automatically; however, ......
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