Closed vic closed 11 years ago
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
Thanks for your contribution!
@sternhenri PrivatePub.unsubscribe('/hello/world')
would unsubscribe you from the /hello/world
channel. You can always obtain the faye subscription object itself if you provide a channel name to the PrivatePub.subscription
function.
@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.