ryanb / private_pub

Handle pub/sub messaging through private channels in Rails using Faye.
MIT License
864 stars 228 forks source link

Manually Removing Subscription #16

Open ryanb opened 13 years ago

ryanb commented 13 years ago

In some applications it may be necessary to prevent the user from listening to a channel before his signature has expired.

Imagine a multi-room chat application. Say a user enters a room and gets a signature to listen to the channel /room/123 and then leaves the room. It is still possible for him to listen to that channel until his signature expires. It would be nice if the Rails app could unsubscribe the user from a room.

# when user leaves the room
unsubscribe_to "/room/123"

To accomplish this Private Pub needs to be told some unique identifier about the user/session.

# before filter
PrivatePub.extra = current_user.id

This information will then need to be passed through the subscribe_to and unsubscribe_to calls to verify the subscription on each published message.

The only tricky part is handling the state of the unsubscribed users. I could do this in-memory on the Faye rack instance, but something more persistent may be necessary.

Before I add this, does anyone have a need for this kind of feature? I think the one-hour expiration will be enough for the majority of the applications.

avucic commented 12 years ago

Yes, it would be very nice...I'm currently working on "multichannel" application using your great private_pub.Channels are stored into the db, and user can part or leave the channel...Thanks and regards

antek-drzewiecki commented 12 years ago

I was going to give a try to implement this feature, but since you are allready on it. This would be a welcomed feature, especially because it fixes the following issue:

A user opens a page, subscribes for notifications, for example chat. The user logs out and then presses the back button on the browser. The browser loads a cached instance of the page (or got a cached page served), where the javascript states that the user listens to the channel. The user will continue listening to the notifications send to the user, for example new chat messages.

Also, this might be a nice feature to know what users are currently listening to the channel? This allows you to know if a user is online or not...

EricSlick commented 12 years ago

I'm working on an app that tails server logs through the browser. The ability to unsubscribe to a channel would be extremely useful to me....even essential since there are many different logs that could potentially be tailed and the user will want to turn tailing on and off at will.

Before seeing this issue, I was tinkering with the code to see how this might be done. Have you made any progress on implementing this feature?

bhernez commented 11 years ago

For the app I'm currently working on, this feature would be awesome and kind of necessary, is there any progress about implementing this feature?