簡體   English   中英

websocket-rails生產中無連接

[英]websocket-rails no connections in production

我正在使用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

正如這里所指出的, websocket-rails不是一個活動的項目,它的最后提交是很久以前的。

我建議使用FayePlezi等替代方法

在Plezi的讀取文件中探討了如何將Plezi應用程序與Rails連接起來,並且似乎很容易實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM