websocket-rails connection initialization - dispatcher.state stuck on "connecting" -
websocket-rails connection initialization - dispatcher.state stuck on "connecting" -
i trying set basic websocket client ror app. i've used websocket-rails gem matter.
i've set simple eventmap mapping. config/events.rb:
websocketrails::eventmap.describe namespace :tasks subscribe :create, :to => taskcontroller, :with_method => :create end end
and simple controller: app/controller/task_controller.rb:
class taskcontroller < websocketrails::basecontroller def create puts "in task create" send_message :create_success, task, :namespace => :tasks end end
and initialization client side:
$(function() { var task = { name: 'start taking advantage of websockets', completed: false } var dispatcher = new websocketrails('localhost:3000/websocket'); dispatcher.on_open = function(data) { alert("on_open"); console.log('connection has been established: ', data); // can trigger new server events within callback if wish. } $("#ws-test").click(function() { dispatcher.trigger('tasks.create', task); }); dispatcher.bind('tasks.create_success', function(task) { console.log('successfully created ' + task.name); }) });
when accessing page triggers code, in network traffic see request ws://localhost:3000/websocket. request returned status code 101 switching protocols. no errors in js nor logs on server side.
this confused. rfc 101 means handshake succeeded, thought connection initialization finished fine. however, when inspecting , debugging client side, dispatcher.state remains in "connecting". when trying invoke dispatcher.trigger, nil happens. when debugging websocket-rails inner code, during trigger there check dispatcher.state , in case it's not "connected", pushes queue instead of proceeding handle it.
and how it's stuck forever. tested on mozilla firefox 33.0 , on chrome version 38.0.2125.104
any insights appreciated.
ruby 2.0.0p576 rails 4.1.1 websocket-rails-0.7.0
ruby-on-rails websocket
Comments
Post a Comment