我正在使用 ActionCable,并在每 3 秒间隔后从服务器接收 ping(在 ActionCable 库中提到)。 我的问题是:如何更改订阅时的 ping 间隔?
有什么想法吗?
最佳答案
扩展@BoraMa的答案:
您可以像这样覆盖后端的常量:
# config/initializers/action_cable.rb
module ActionCable
module Server
module Connections
BEAT_INTERVAL = 5
end
end
end
在客户端,您还需要覆盖该值:
// this should be after //= require action_cable
// but before any App.cable.subscriptions.create call
// the value here *must* be 2 times the backend's value
ActionCable.ConnectionMonitor.staleThreshold = 10;
请注意,这种方法通常是一个非常糟糕的主意:弄乱内部变量是导致错误和问题的直接方法之一。
事实上,Ruby 甚至会警告您:
config/initializers/action_cable.rb:7: warning: already initialized constant ActionCable::Server::Connections::BEAT_INTERVAL
仅当您知道自己在做什么时才使用此选项。
关于ruby-on-rails - 如何更改 Action 电缆 rails 中的 ping 间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37343163/