Reputation: 703
I am building an app with Laravel, and use Pusher to send notification to users. The notifications will send to users when someone make an event.
Ex: Like event, comment event,...
I already completed send noti with Pusher, but it send to all user. So I want to send noti to group of user when Event fired.
Ex: when someone comment on your post, I just want app send noti to you(owner) and all user already has commented on that post.
My code call Pusher:
var pusher = new Pusher('MY_KEY', {
encrypted: true,
cluster: 'us2'
});
// Comment event channel
var channel = pusher.subscribe('private-commented-event');
channel.bind('App\\Events\\PostWasCommented', function(data) {
alert('Post was commented!');
});
Any idea with Pusher?
p/s: I already research about private and presence channel but it not true in my case.
Upvotes: 1
Views: 1155
Reputation: 304
Firstly let's review:
Channels are things that users can subscribe to. They don't have to, they just can. Events are things that are passed to users through a Channel. Only users subscribed to said channel will receive said event.
A user can be subscribed to one or more channels. So, in your case, it sounds as if currently you have all your users subscribed to one channel. Why not also subscribe each user to their own channel? There is no limit nor any need to limit the number of channels you can have, so this is fine. Then, if you wish for all users to be notified you can push to the channel where they're all subscribed, but if you want only a specific user to be notified, you can push the event to the channel that just they're subscribed to.
In terms of keeping track - my advice would be to name the channels using the User ID.
Remember, any number of users can be subscribed to any number of channels. Hopefully that helps!
Upvotes: 1