Live timelines using ActionCable
This commit is contained in:
parent
10ba09f546
commit
6deb9f966e
24 changed files with 99 additions and 53 deletions
5
app/channels/application_cable/channel.rb
Normal file
5
app/channels/application_cable/channel.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
|
||||
module ApplicationCable
|
||||
class Channel < ActionCable::Channel::Base
|
||||
end
|
||||
end
|
20
app/channels/application_cable/connection.rb
Normal file
20
app/channels/application_cable/connection.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
|
||||
module ApplicationCable
|
||||
class Connection < ActionCable::Connection::Base
|
||||
identified_by :current_user
|
||||
|
||||
def connect
|
||||
self.current_user = find_verified_user
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_verified_user
|
||||
if verified_user = env['warden'].user
|
||||
verified_user
|
||||
else
|
||||
reject_unauthorized_connection
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
10
app/channels/timeline_channel.rb
Normal file
10
app/channels/timeline_channel.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
|
||||
class TimelineChannel < ApplicationCable::Channel
|
||||
def subscribed
|
||||
stream_from "timeline:#{current_user.id}"
|
||||
end
|
||||
|
||||
def unsubscribed
|
||||
# Any cleanup needed when channel is unsubscribed
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue