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.
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.
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.