-
Notifications
You must be signed in to change notification settings - Fork 225
private_pub.js subscription callback and unsubcribe function. #60
Conversation
If options given to `sign` include a `subscription` function, it will be called with the newly created subscription object. This way users can add a Faye callback to know when a subscription is ready or cancel a subscription in the future.
…bject. Store subscription objects on an internal object and expose three new methods: `subscription(channel)`, `unsubscribe(channel)` and `unsubscribeAll()`
I tried this out and it works pretty good... is there a way to get PrivatePub to publish a "subscription" message on the channel that was subscribed to? |
Hey, Sure you can, I mean, on the client side when you're signing to a channel, you can pass a callback that will be called whenever the subscription is successful. (See https://github.com/vic/private_pub/blob/a0abfba2ca774303e00321f9565ec99fea7dc97c/spec/javascripts/private_pub_spec.js#L66 ) // on privatepub this data is sent by server to client
var opts = {
server: "foo",
channel: "/hello/world",
...
}
// and you can add a subscription callback
// it will take a Faye subscription object. (see http://faye.jcoglan.com/browser/subscribing.html)
opts.subscription = function(subscription) {
subscription.callback(function() {
// subscription was successful here.
// send an initial message on that channel.
PrivatePub.faye(function(faye){
faye.send("/hello/world", {text: 'Hey I just connected!'});
});
});
}
PrivatePub.sign(options) something like that. (havent tried it but hope that shows the path) |
+1 |
private_pub.js subscription callback and unsubcribe function.
Thanks for your contribution! |
@sternhenri |
@vic Hmm. I'm running 1.0.3 (latest version I think) and couldn't find the function when I tried to run it in the rails console... I'll look further :D. Thanks! |
@sternhenri just to be clear, the examples I mentioned earlier are for javascript client side code, once the client is connected to a channel and wants to unsubscribe, so you wont find them at the rails console. |
Hi,
I worked on solving issues #45, #37.