1

I installed the 'websocket-rails' gem and after doing the default configuration I just created a JS dispatcher and I get a 404 error on chrome console.

This is my JS:

var dispatcher = new WebSocketRails('localhost:3000/websocket');

This is the message I get:

WebSocket connection to 'ws://localhost:3000/websocket' failed: Error during WebSocket handshake: Unexpected response code: 404

Everything else is as suggested by the first-steps-guide

events.rb

subscribe :test, :to => ChatServerController, :with_method => :test

controller/chat_server_controller.rb

class ChatServerController < WebsocketRails::BaseController
  def initialize_session
    # perform application setup here
    controller_store[:message_count] = 0
  end

  def test
      puts 'Hello'
  end
end
Victor Ferreira
  • 6,151
  • 13
  • 64
  • 120
  • 1
    Considering your new question http://stackoverflow.com/q/37285483/1212000, is this one still valid? If you found a solution to your problem on your own, please consider helping people with a similar problem by providing an answer to this question yourself and accepting it. – Raffael May 18 '16 at 00:48
  • you're right. Unfortunately I didn't manage to solve this problem and implemented a new version of that feature using the private_pub (https://github.com/ryanb/private_pub) gem – Victor Ferreira May 30 '16 at 16:59

1 Answers1

1

There's one potential solution involving a gem dependency posted on github. But, if you look at the repo (151 open issues, 27 pull requests), it doesn't look like this gem is being actively maintained. The closed issues in 2016 are being closed by the same people who opened them.

You can probably make your application work by forcing websockets to use http by including a second parameter, set to false.

var Dispatcher = new WebSocketRails('localhost:3000/websocket', false);

I have concerns about how scalable using http polling will be and about the future of the websocket-rails gem. For me, it seems like the best way forward is to upgrade to Rails 5 and use Action Cable.

Community
  • 1
  • 1
Cleverlemming
  • 1,310
  • 1
  • 8
  • 10
  • thanks for taking your time. as you said, the gem hasnt been updated and I only found a critical difficulty when I installed it in a different environment. I used a different gem (private_pub) and now I got this feature working. – Victor Ferreira May 30 '16 at 17:02