about summary refs log tree commit diff
path: root/app/channels
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-08-18 15:49:51 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-08-18 15:49:51 +0200
commit6deb9f966eb9a280cc16428ba9324ffc15ea60a8 (patch)
treeec3574856544cad4766a6bb93905089d8086db0a /app/channels
parent10ba09f5466fe3d34a5ed78202c35f4e4f9d30e6 (diff)
Live timelines using ActionCable
Diffstat (limited to 'app/channels')
-rw-r--r--app/channels/application_cable/channel.rb5
-rw-r--r--app/channels/application_cable/connection.rb20
-rw-r--r--app/channels/timeline_channel.rb10
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