我使用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
endhttps://stackoverflow.com/questions/30265047
复制相似问题