【问题标题】:websocket-rails no connections in productionwebsocket-rails 在生产中没有连接
【发布时间】:2015-05-15 17:04:58
【问题描述】:

我正在使用 websocket-rails gem 将 websocket 连接到我的 rails 应用程序 - 它在我的计算机上完美运行 - 但在我的生产机器上它无法运行。

当我连接时 - 它写入 websocket_rails 日志 - 我已连接 - 但是当我尝试向连接发送数据时 - 它什么也不做。

我添加了一些日志来帮助我找到问题,似乎 WebsocketRails.users 是空的 - 意味着没有连接 - 即使有。

但是,当我真正断开 websocket 连接时,它会记录断开连接 - 并查看代码,它会在记录断开连接之前检查它是否已连接 - 所以我发现它已连接。

这是触发连接事件的代码

class Route < ActiveRecord::Base
  acts_as :user
  has_many :students

  after_update  :notify_location_changed, if: Proc.new { |route| route.loc_latitude_changed? || route.loc_longitude_changed? }

  def notify_location_changed
    logger.info "#{self.id} location_updated"
    logger.info "connections: #{WebsocketRails.users.users}" #this is empty - even when there is a connection open - it still pings.
    channel = WebsocketRails[self.id.to_s]
    WebsocketRails.logger.info "sending to the following subscribers of channel #{self.id} - #{channel.subscribers}"
    channel.subscribers.each do |connection|
      logger.info "sending to the following connection #{connection}"
      options = {}
      logger.info "#{connection.data_store}"
      user = connection.data_store[:user].actable
      logger.info "user: #{user.to_json}"
      data = [loc_latitude: loc_latitude - user.pick_up_lat, loc_longitude: loc_longitude - user.pick_up_long].to_json
      options.merge! :channel => channel.name, :token => channel.token
      options[:data] = data
      event = WebsocketRails::Event.new :location_updated, options
      connection.trigger event
    end
  end
end

【问题讨论】:

    标签: ruby-on-rails ruby websocket


    【解决方案1】:

    正如here 指出的那样,websocket-rails 不是一个活跃的项目,它的最后一次提交是很久以前的事了。

    我建议使用 FayePlezi 等替代方法。

    在 Plezi 的读取文件中探讨了将 Plezi 应用程序与 Rails 连接,并且看起来很容易完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 2016-01-24
      • 1970-01-01
      • 2019-09-23
      相关资源
      最近更新 更多