websocket-rails 在生产中没有连接 [英] websocket-rails no connections in production

查看:35
本文介绍了websocket-rails 在生产中没有连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 websocket-rails gem 将 websocket 连接到我的 rails 应用程序 - 事情是它在我的计算机上完美运行 - 但在我的生产机器上它就行不通了.

I am using websocket-rails gem for websocket connection to my rails app - the thing is it works perfectly on my computer - but on my production machine it just won't work.

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

when I connect - it writes to websocket_rails log - that I am connected - however when I try to send data to the connection - it does nothing.

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

I added some logs to help me find the issue, and it seems WebsocketRails.users is empty - meaning there are no connections - even though there are.

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

however, when I really disconnect from the websocket connection, it logs the disconnection - and seeing the code, it checks if it's connected before logging the disconnection - so i finds it connected.

这是在连接上触发事件的代码

this is the code that triggers an event on the connection

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

推荐答案

此处所指出的,websocket-rails 不是一个活跃的项目,它的最后一次提交是在很久以前.

As pointed out here, websocket-rails isn't an active project and it's last commit was a long time ago.

我建议使用替代方法,例如 FayePlezi.

I would recommend using alternatives such as Faye or Plezi.

Plezi 的读取文件中探讨了将 Plezi 应用程序与 Rails 连接,这似乎很容易实现.

Connecting a Plezi app with Rails is explored in the Plezi's read file and seems quite easy to accomplish.

这篇关于websocket-rails 在生产中没有连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆