diff options
Diffstat (limited to 'app/channels')
-rw-r--r-- | app/channels/application_cable/channel.rb | 5 | ||||
-rw-r--r-- | app/channels/application_cable/connection.rb | 20 | ||||
-rw-r--r-- | app/channels/timeline_channel.rb | 10 |
3 files changed, 35 insertions, 0 deletions
diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 000000000..d56fa30f4 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -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 diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 000000000..f7cbe5485 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -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 diff --git a/app/channels/timeline_channel.rb b/app/channels/timeline_channel.rb new file mode 100644 index 000000000..c128fae58 --- /dev/null +++ b/app/channels/timeline_channel.rb @@ -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 |