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:
- Created 3 years ago
- Comments:17 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey can you please re-share that repo ? I have the same issue
Okay I got it working. A couple of things:
pusher
(see the docs): https://github.com/farshidahmadianpin/laravel-echo/blob/main/.env.example#L17['middleware' => ['auth']]
here. Not sure why you added that. https://github.com/farshidahmadianpin/laravel-echo/blob/main/app/Providers/BroadcastServiceProvider.php#L17Hope that helps.