mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
splitting out a bit of ruby from some coffeescript that it was grouped with
This commit is contained in:
parent
f300627b68
commit
d8d733f76e
1 changed files with 6 additions and 4 deletions
10
README.md
10
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
|
||||
|
|
Loading…
Reference in a new issue