From d8d733f76eaea0c88ee33076b4dbe244f27a2240 Mon Sep 17 00:00:00 2001 From: Charles DuBose Date: Mon, 12 Oct 2015 21:43:48 -0500 Subject: splitting out a bit of ruby from some coffeescript that it was grouped with --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 74b0cea8ca..aa3d6101df 100644 --- a/README.md +++ b/README.md @@ -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 -- cgit v1.2.3