I have been using Faye on 2.1.3 with no problems, but upon upgrading to 2.2.2 I can only get local instance to work. Production websockets fail. I replaced the actual server name with blahblahserver.com
Faye Rackup
require 'faye'
app = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
Faye::WebSocket.load_adapter('thin')
run app
Application.html.erb
<%= javascript_include_tag "application",params[:controller],'http://ift.tt/1fbf1dG','data-turbolinks-track' => true %>
Helper (send function)
def broadcast(channel, &block)
message = {:channel => channel, :data => capture(&block)}
uri = URI.parse("http://localhost:9292/faye")
Net::HTTP.post_form(uri, :message => message.to_json)
end
In Rails Controller
gon.env = Rails.env
Listener (Coffeescript)
$ ->
# required when faye listener is present to keep from having hard env changes
# parallel gon.env = Rails.env in controller must be present
server_name = undefined
switch gon.env
when "production"
server_name = 'app-server1.blahblahserver.com'
when "staging"
server_name = 'si-staging.blahblahserver.com'
when "development"
server_name = 'localhost'
address = 'http://' + server_name + ':9292/faye'
# Listener for this page locally
faye = new (Faye.Client)(address)
faye.subscribe ('/logs/'+gon.property_id+ '/new'), (data) ->
if getParameterByName('all_open') == "true"
window.location.href = window.location.href
else if gon.today == gon.display_date
ready(data)
else window.location.href = window.location.href
return
faye.subscribe ('/logs/'+gon.property_id+ '/alert'), (data) ->
console.log('pre-ajax')
$.ajax 'load_customer_messages' ,
type: "GET",
dataType: "JSON",
asnyc: false,
success: (data2) ->
$('#ajax').click()
return
return
ready = (data) ->
eval data
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire