操作电缆:通知单个用户

时间:2016-09-08 14:14:58

标签: ruby-on-rails ruby websocket actioncable

我正在构建一个聊天应用程序,用户可以在其中私下聊天。我被困在以下几点:

  • '用户A'点击'用户B'聊天图标,现在我们需要向单个用户B发送通知。怎么能实现这个目标呢?
  • '用户A'有N个朋友。当用户A'脱机,如何只通知系统中的N个朋友?

一般来说,如何向有限数量的连接用户发送通知?

1 个答案:

答案 0 :(得分:2)

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

    identified_by :uuid

    def connect
      # feel free to use any methods to store and match this
      # uuid with current user
      self.uuid = SecureRandom.uuid
    end
  end

然后在你的应用的任何部分:

ActionCable.server.broadcast user_uuid, data