Unable to get notification broadcasted to pusher

First let me start by listing what I have done and tried. I have pretty much everything working with the exception of the event being sent to pusher, and I have looked here and on discord and while there are a few questions related to this, most are just dead since the OP never replied back. -Pusher configuration is setup and correct -Echo is setup -Pusher SDK is installed Upon saving a form, I am using this to dispatch the event: DatabaseNotificationsSent::dispatch($recipient); I also tried this first per the docs, but they should be equivalent event(new DatabaseNotificationsSent($recipient)); I can see in my logs that the event fires up, and on the pusher dashboard I can see 3 events: 1.Connection 2.Subscribed 3.Occupied But I am not able to see the actual event. My config/filament.php file has the code below which I had it commented it out until my last 2 tries because I was initializing echo inside a custom js file that I am loading in my app layout file: 'broadcasting' => [ 'echo' => [ 'broadcaster' => 'pusher', 'key' => env('VITE_PUSHER_APP_KEY'), 'cluster' => env('VITE_PUSHER_APP_CLUSTER'), 'forceTLS' => true, ], ], My custom js file has this: 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_CLUSTER, forceTLS: true }); const userId = window.userId; window.Echo.private(App.Models.User.${userId}) .listen('.database-notifications.sent', (e) => { console.log("Event received:", e); }); Anyone has been able to successfully get the database notifications to work with pusher? I have them working with the default polling but cant get it to work with Echo/Websockets.
3 Replies
rg.block
rg.blockOP15mo ago
While I continue to try to get this to work, I found a discussion about broadcast notifications on github. Not directly database notifications but the core should be the same. Dan mentions that filament takes care of loading Echo. So with that, I have removed my custom js file, and inside my component blade file I added this to listen to the event: window.onload=function(){ Echo.private('App.Models.User.${userId}') .listen('.database-notifications.sent', (e) => { console.log(e); }); } The issue is that Echo shows as undefined. Mind it, I suck as js so I could be missing something super basic, but I believe I have followed everything step by step (filament docs, Echo/broadcasting and pusher docs). Even more weird is that either people dont really have issues with this, or not a lot of them are using it since the questions related to this are not a lot, and the ones here and on github are pretty much unanswered.
filament_newbie
filament_newbie14mo ago
have you solve the problem yet? i solve it by put these code in base.blade.php <script type="module"> if (window.Echo) { Echo.private('App.Models.User.${userId}') .listen('.database-notifications.sent', (e) => { console.log(e); }); } </script> pusher have some readings but still doesn't do real time notification
Jon Mason
Jon Mason13mo ago
@rg.block @filament_newbie Has anyone figured this out? I'm beating my head against a wall here with broadcast notifications. Looks like filament is adding an EchoLoaded event, so I copied that over to my blade file to try and see what's coming back, which kind of works:
<script>
window.addEventListener('EchoLoaded', (event) => {
console.log(event); <--logs value
console.log('EchoLoaded'); <--logs value
window.Echo.private('App.Models.User.1').listen('.database-notifications.sent', () => {
console.log('database-notifications.sent') <--never gets here
})
})
</script>
<script>
window.addEventListener('EchoLoaded', (event) => {
console.log(event); <--logs value
console.log('EchoLoaded'); <--logs value
window.Echo.private('App.Models.User.1').listen('.database-notifications.sent', () => {
console.log('database-notifications.sent') <--never gets here
})
})
</script>
Seems like it's not "hearing" the .database.notifications.sent event. I would think that filament already handles the event listener and displaying the notification, so i must be missing something.
Want results from more Discord servers?
Add your server