【问题标题】:Rails 5 ActionCable modify confirm_subscriptionRails 5 ActionCable 修改confirm_subscription
【发布时间】:2017-06-16 16:48:01
【问题描述】:

我得到了这个频道:

class TestChannel < ApplicationCable::Channel
  def subscribed
    stream_from 'test'

    ActionCable.server.broadcast 'Test', vehicles: Vehice.find_by id: 13
  end
end

当有人订阅时,我不想向所有订阅者广播。 我正在考虑通过添加'message' 来更改confirm_subscription

有人能告诉我这是否可能吗?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-5 actioncable


    【解决方案1】:

    您可以使用transmit 仅向当前订阅发送消息。它并没有真正记录在案,并且在某种程度上是一种反模式(因为在 pub sub 场景中,频道中的每条消息都应该到达每个用户),但它工作正常。当客户端发送无效请求时,我们使用它来“响应”错误消息。

    【讨论】:

      猜你喜欢
      • 2017-01-04
      • 1970-01-01
      • 2016-11-22
      • 2021-09-29
      • 2017-03-13
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多