i'm trying use websocket-rails broadcast live routes come in site. however, i'm unable messages published. i've read of find, , can't seem solution.
here javascript have in application.html.erb:
var route_name = window.location.pathname + window.location.search; $.post("/realtimeroutes", { data: { route_name: route_name} }, function(response) { } ); this data handed off rails controller method realtime_routes looks this:
def realtime_routes puts '*** route data is: ' + params[:data][:route_name]); new_route = routecatcher.new(route_name: params[:data][:route_name] if new_route.save route = {route_name: params[:data][:route_name]} puts '*** right before message sent ***' websocketrails[:new_route].trigger('new', route) puts '*** right after message sent ***' render nothing: true else render nothing: true end end to point fine. updates happening in db , both before , after messages printing console, there no websocket message fired.
next have javascript listening in realtime.html.erb:
var dispatcher = new websocketrails(window.location.host + '/websocket'); var channel = dispatcher.subscribe('new_route'); channel.bind('new', function(route) { console.log('********** inside bind event'); console.log('********** new route '+ route.route_name +' arrived!'); }); nothing ever being received on bind event , when in console on chrome, get:
'uncaught referenceerror: websocketrails not defined' so i'm absolutely stuck here i've followed every bit of documentation can find , have no idea go. appreciated.
update: initialization error because websocketrails being rendered before rest of application js.
however, getting error:
websocket connection 'ws://localhost:3000/websocket' failed: error during websocket handshake: unexpected response code: 301 after reading further other people same error, seems prudent mention using puma on aws elasticbeanstalk ssl in production.
Comments
Post a Comment