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 sessionObj.channel.unsubscribe(channel_name)
ss.api.session.find(sessionID, socketID?, cb)
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.
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.
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.
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. :)
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.
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.
This shouldn't be a problem. I will attempt an implementation this week.
@kulicuu Thanks, I'll assign to you.