0

I'm working on a blog and the idea is to get real-time notifications as soon as somebody writes a comment to one of my posts (like on Facebook or similar social media). I've tried to do this with ActionCable feature and everything seems working, but the notifications are seen not only by me, but by everybody who is on the blog now.

I've also tried to add this part of code from the official documentation to make the private channel:

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verfied_user
    end

    protected

    def find_verfied_user
      if current_user = env['warden'].user
        current_user
      else
        reject_unauthorized_connection
      end
    end
  end
end

It worked, but when somebody except the administrator is reading the blog, server keeps polling and rejecting the connection every 20 seconds which is an extra load for the server.

I wonder if there's some way to tell ActionCable to broadcast notifications only to specific user (in that case to me as an administrator) and not to be seen by anybody else? Or is there a better way to do that using other features like Faye? Thanks in advance.

staniel
  • 3
  • 3
  • Disclaimer: I have no experience with ActionCable. Why are the connection polled every 20 seconds? I was under impression that web-sockets keep the connection open (like logging in with with remote ssh) – Ruslan Mar 29 '17 at 14:24
  • According to server logs, ActionCable keeps trying to upgrade WebSocket from client side, but for those who are not administrator the connection is closed, so WebSocket upgrade fails and somehow restarts again and again. Maybe I'm doing something wrong. – staniel Mar 29 '17 at 14:40

0 Answers0