ruby-on-rails – 如何更改动作电缆轨道中的ping间隔

我正在使用ActionCable并在每3秒间隔(在ActionCable库中提到)接收来自服务器的ping.
我的问题是:如何在订阅时更改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

只有当你知道自己在做什么时才使用它.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...