Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionCable: One channel per user

I am working on notifications for my rails app. There is User model and controller and Like model associated to User with a User has many Likes association.

The idea is, if a user likes the profile of another user, owner of the profile will get a live notification.

This is my app for understanding ActionCable. I studied the cable api, pub-sub was new to me. I was able to make successful communication through a single channel, and also successfully used the authorization. But, still I don't understand how to use single channel per user (dynamically generated channel), so that message posted to one user doesn't go to another user.

Is dynamic channel possible?

Or, are there other ways where a single channel satisfies all the users needs

like image 380
Will Avatar asked May 19 '16 08:05

Will


1 Answers

The solution was actually simple, but some new terms introduced in ActionCable made it confusing. By the way, here's how I solved it.

I used a single channel but multiple streams for different users. Here's the ActionCable documentation link that clearly states a very identical scenario. I went through the documentation earlier, but somehow I didn't understand it at the first glance.

Sorry for not providing any direct code, I think the documentation will explain it totally.

like image 77
Will Avatar answered Sep 27 '22 22:09

Will