ryanb / private_pub

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

Alternative JavaScript callback function #1

Closed ryanb closed 13 years ago

ryanb commented 13 years ago

By default the JavaScript is passed to eval, but some like to manage it through JSON. There should be an alternative syntax for supplying a callback function to a given subscription. Here's what the documentation could look like:

Alternatively you can pass anything you want to the publish_to method (it will be converted to_json).

  publish_to "/messages/new", :chat_message => "hello world"

And then handle that in a callback in JavaScript.

  PrivatePub.subscribe("/messages/new", function(data) {
    $("#chat").append(data.chat_message);
  });

Note: the subscribe_to call is still necessary with this approach to grant the user access to that channel. The JavaScript is just a callback.

ryanb commented 13 years ago

Closed thanks to BinaryMuse in issue #9