An ability to unsubscribe a user from a channel #166

nponeccop opened this Issue Feb 28, 2012 · 12 comments


None yet

8 participants


It is possible to send events to a userId. Is it possible to subscribe/unsubscribe a user?

Use case: consider my TV example from #157. If a user's subscription has expired, it must stop watching paid channels immediately. So a server, on a cron event, checks user database for expired accounts, and calls something like ss.unsubscribeUser(userId, channel_name) for each account which expired since the previous check.

Socketstream then finds all sessions of a user and unsubscribes them from the listed channels.


Perhaps you would have the current sessionID saved for each of your users, and then you would fetch the session object first from the Connect session store via ss.api.session.find(sessionID, socketID?, cb), but I don't know what happens when the socketID is then null for such requests. But with the session object, one could then call

Or one could send some kind of "forceSubscriptionRenewal" request to the browser, which must then ask for a subscription renewal from the server, before a timeout occurs. Then in a request responder one can unsubscribe or renew the subscription.

owenb commented Jul 25, 2012

Hi all

Thanks for this, and apologies for the late reply.

Having given this some thought I think it's pretty clear we need a few API calls on the collections of 'users', and 'channels' - and maybe 'sessions' as well.


// get a list of socketIds in use by a particular userId (will also tell you how many devices this userId is using)
ss.users.find(userId) -> [array of socketIds]

// get a list of socketIds in use by a particular sessionId (i.e. how many open tabs)
ss.sessions.find(sessionId) -> [array of socketIds]

// unsubscribe all sockets (devices) attached to this userId (effectively logging the user out of all devices simultaneously) 
ss.users.unsubscribeAll(userId) -> true

// get a list of sockets subscribed to a particular channel
ss.channels.find(channelName) -> [array of socketIds]

// unsubscribes all sockets from the named channel
ss.channels.unsubscribeAll(channelName) -> true

Too late to put them into 0.3 now, but I'll earmark this for 0.4. Of course the actual API may change - I'll have to give it more thought. Suggestions welcome.


I'm giving this a bump to remind myself of the value of some of these items—I think they may actually need to happen in SS 3, and I'll be willing to work on them.

owenb commented Jul 27, 2013

Hey Robert

That would be awesome if you could add these changes to 0.3. In fact, if you could do that and update the dependencies, I'm happy to do another 0.3 release.

Let me know if you run into any problems.



Yes, we have an immediate need. Right now the approach is to go to the connect/middelware layer and figure it out. So, getting into the grit of it helps, and then I could abstract it out a level.

@paulbjensen paulbjensen was assigned Oct 23, 2013

I'm going to have a look at getting this in before 0.3.11 is released.


That would be epic. Sorry I never got to it. :)

luksch commented Dec 12, 2013

any news on this? I am now facing the same requirements



There is a feature branch, but it's still a work in progress. I will have a look into it this weekend. Apologies for the delay, if only I could work on SocketStream full time.

luksch commented Dec 12, 2013

thx a lot for a the time and effort you put into this. I really appreciate this. We built our application on socketstream and really hope that the project continues to fly. Unfortunately we don't have any resources to get active here. Maybe there will be time for that in the future, but right now I can't help with any of that - I just want to use it :) so I understand that you can't do everything at once.

@paulbjensen paulbjensen modified the milestone: 0.3.12, 0.3.11 Feb 1, 2015
kulicuu commented Feb 3, 2015

This shouldn't be a problem. I will attempt an implementation this week.


@kulicuu Thanks, I'll assign to you.

@paulbjensen paulbjensen assigned kulicuu and unassigned paulbjensen Feb 3, 2015
@thepian thepian modified the milestone: 0.4.x, 0.3.12 Mar 31, 2015
@thepian thepian modified the milestone: 0.4.1, 0.4.x Apr 16, 2015
@thepian thepian modified the milestone: 0.4.x, 0.4.3 Jun 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment