diff options
author | Charles DuBose <kayakyakr@gmail.com> | 2015-10-12 21:43:48 -0500 |
---|---|---|
committer | Charles DuBose <kayakyakr@gmail.com> | 2015-10-12 21:43:48 -0500 |
commit | d8d733f76eaea0c88ee33076b4dbe244f27a2240 (patch) | |
tree | ded9a6477df1770434c279c8b5fb87e2a7e4b891 | |
parent | f300627b68f61489f681328a9ce0b12c9eea0402 (diff) | |
download | rails-d8d733f76eaea0c88ee33076b4dbe244f27a2240.tar.gz rails-d8d733f76eaea0c88ee33076b4dbe244f27a2240.tar.bz2 rails-d8d733f76eaea0c88ee33076b4dbe244f27a2240.zip |
splitting out a bit of ruby from some coffeescript that it was grouped with
-rw-r--r-- | README.md | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -186,16 +186,18 @@ class WebNotificationsChannel < ApplicationCable::Channel ``` ```coffeescript -# Somewhere in your app this is called, perhaps from a NewCommentJob -ActionCable.server.broadcast \ - "web_notifications_#{current_user.id}", { title: 'New things!', body: 'All the news that is fit to print' } - # Client-side which assumes you've already requested the right to send web notifications App.cable.subscriptions.create "WebNotificationsChannel", received: (data) -> new Notification data['title'], body: data['body'] ``` +```ruby +# Somewhere in your app this is called, perhaps from a NewCommentJob +ActionCable.server.broadcast \ + "web_notifications_#{current_user.id}", { title: 'New things!', body: 'All the news that is fit to print' } +``` + The `ActionCable.server.broadcast` call places a message in the Redis' pubsub queue under a separate broadcasting name for each user. For a user with an ID of 1, the broadcasting name would be `web_notifications_1`. The channel has been instructed to stream everything that arrives at `web_notifications_1` directly to the client by invoking the `#received(data)` callback. The data is the hash sent as the second parameter to the server-side broadcast call, JSON encoded for the trip |